Skip to content

Commit

Permalink
feat: introduce new monetary int (#310)
Browse files Browse the repository at this point in the history
* feat: introduce new monetary int type

* fix: apply suggestions from code review

Co-authored-by: Antoine Gelloz <antoine.gelloz@me.com>
Signed-off-by: Clément Salaün <salaun.clement@gmail.com>

* fix: remove comment in pkg/ledger/process_test.go

Co-authored-by: Antoine Gelloz <antoine.gelloz@me.com>
Signed-off-by: Clément Salaün <salaun.clement@gmail.com>

* chore: clean

* feat: Make verbose configurable on tests

* feat: use dotenv on Taskfile to allow developpers to have their own set of parameters

* chore: remove useless file

* fix: remove binary and change verbose to bool

* fix: after merge

Signed-off-by: Clément Salaün <salaun.clement@gmail.com>
Signed-off-by: Ragot Geoffrey <geoffrey.ragot@gmail.com>
Co-authored-by: Antoine Gelloz <antoine.gelloz@me.com>
Co-authored-by: Geoffrey Ragot <geoffrey.ragot@gmail.com>
  • Loading branch information
3 people authored Aug 31, 2022
1 parent 8215ff2 commit bbd082a
Show file tree
Hide file tree
Showing 42 changed files with 774 additions and 902 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ cmd/control/*
vendor
sdk/swagger.yaml
sdk/swagger.yaml-e
sdk/sdks
sdk/sdks
.vscode
.env
41 changes: 22 additions & 19 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# https://taskfile.dev

version: '3'
version: "3"

dotenv:
- .env

vars:
PKG: "./..."
Expand All @@ -17,11 +20,11 @@ tasks:

lint:
cmds:
- golangci-lint run -v --fix
- golangci-lint run --fix {{if eq .VERBOSE "true"}}-v{{end}}

tests:
cmds:
- go test {{.TAGS}} -v -coverpkg {{.PKG}} -coverprofile coverage.out -covermode atomic {{.PKG}}
- go test {{.TAGS}} {{if eq .VERBOSE "true"}}-v{{end}} -coverpkg {{.PKG}} -coverprofile coverage.out -covermode atomic {{.PKG}}

tests:local:
cmds:
Expand All @@ -31,7 +34,7 @@ tasks:
tests:local:sqlite:
cmds:
- >
go test {{.TAGS}} -v {{.FAILFAST}} -coverpkg {{.PKG}} -coverprofile coverage.out -covermode atomic
go test {{.TAGS}} {{if eq .VERBOSE "true"}}-v{{end}} {{.FAILFAST}} -coverpkg {{.PKG}} -coverprofile coverage.out -covermode atomic
-run {{.RUN}} -timeout {{.TIMEOUT}} {{.PKG}} |
sed ''/PASS/s//$(printf "\033[32mPASS\033[0m")/'' |
sed ''/FAIL/s//$(printf "\033[31mFAIL\033[0m")/'' |
Expand All @@ -42,7 +45,7 @@ tasks:
deps: [postgres]
cmds:
- >
go test {{.TAGS}} -v {{.FAILFAST}} -coverpkg {{.PKG}} -coverprofile coverage.out -covermode atomic
go test {{.TAGS}} {{if eq .VERBOSE "true"}}-v{{end}} {{.FAILFAST}} -coverpkg {{.PKG}} -coverprofile coverage.out -covermode atomic
-run {{.RUN}} -timeout {{.TIMEOUT}} {{.PKG}} |
sed ''/PASS/s//$(printf "\033[32mPASS\033[0m")/'' |
sed ''/FAIL/s//$(printf "\033[31mFAIL\033[0m")/'' |
Expand All @@ -54,7 +57,7 @@ tasks:

bench:
cmds:
- go test {{.TAGS}} -run=XXX -bench=. {{.PKG}}
- go test {{.TAGS}} {{if eq .VERBOSE "true"}}-v{{end}} -run=XXX -bench=. {{.PKG}}

print:coverage:
cmds:
Expand Down Expand Up @@ -88,7 +91,7 @@ tasks:
desc: Extract templates
dir: ./sdk
preconditions:
- sh: "[ \"{{.CLI_ARGS}}\" != \"\" ]"
- sh: '[ "{{.CLI_ARGS}}" != "" ]'
msg: Please specify generator as first cli arg (ie "task template -- go")
cmds:
- >
Expand All @@ -99,7 +102,7 @@ tasks:
desc: Generate client code
dir: ./sdk
preconditions:
- sh: "[ \"{{.CLI_ARGS}}\" != \"\" ]"
- sh: '[ "{{.CLI_ARGS}}" != "" ]'
msg: Please specify generator as first cli arg (ie "task generate -- go")
cmds:
- wget https://raw.githubusercontent.com/numary/ledger/{{.VERSION}}/pkg/api/controllers/swagger.yaml -O swagger.yaml
Expand All @@ -118,7 +121,7 @@ tasks:
desc: Test client code
dir: ./sdk
preconditions:
- sh: "[ \"{{.CLI_ARGS}}\" != \"\" ]"
- sh: '[ "{{.CLI_ARGS}}" != "" ]'
msg: Please specify generator as first cli arg (ie "task test -- go")
- sh: "[[ -e sdks/{{.CLI_ARGS}}/Taskfile.yml ]]"
msg: "Not Taskfile found. You have to create a taskfile in ./sdks/{{.CLI_ARGS}}/ with a 'test' task"
Expand All @@ -138,31 +141,31 @@ tasks:
goreleaser:test:rpm:
desc: Tests rpm packages
vars:
rpm: 'rpm --nodeps -ivh'
rpm: "rpm --nodeps -ivh"
cmds:
- task: goreleaser:test:pkg
vars:
Platform: 'amd64'
Platform: "amd64"
Image: fedora
Cmd: '{{.rpm}} numary_*_linux_amd64.rpm'
Cmd: "{{.rpm}} numary_*_linux_amd64.rpm"
- task: goreleaser:test:pkg
vars:
Platform: 'arm64'
Platform: "arm64"
Image: fedora
Cmd: '{{.rpm}} numary_*_linux_arm64.rpm'
Cmd: "{{.rpm}} numary_*_linux_arm64.rpm"

goreleaser:test:deb:
desc: Tests deb packages
vars:
dpkg: 'dpkg --ignore-depends=git -i'
dpkg: "dpkg --ignore-depends=git -i"
cmds:
- task: goreleaser:test:pkg
vars:
Platform: 'amd64'
Platform: "amd64"
Image: ubuntu
Cmd: '{{.dpkg}} numary_*_linux_amd64.deb'
Cmd: "{{.dpkg}} numary_*_linux_amd64.deb"
- task: goreleaser:test:pkg
vars:
Platform: 'arm64'
Platform: "arm64"
Image: ubuntu
Cmd: '{{.dpkg}} numary_*_linux_arm64.deb'
Cmd: "{{.dpkg}} numary_*_linux_arm64.deb"
3 changes: 1 addition & 2 deletions cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -258,7 +257,7 @@ func NewContainer(v *viper.Viper, userOptions ...fx.Option) *fx.App {
res = append(res, middlewares.Log())
var writer io.Writer = os.Stderr
if v.GetBool(sharedotlptraces.OtelTracesFlag) {
writer = ioutil.Discard
writer = io.Discard
res = append(res, opentelemetrytraces.Middleware())
}
res = append(res, gin.CustomRecoveryWithWriter(writer, func(c *gin.Context, err interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/script_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"

"github.com/numary/machine/script/compiler"
"github.com/sirupsen/logrus"
Expand All @@ -14,7 +14,7 @@ func NewScriptCheck() *cobra.Command {
Use: "check [script]",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
b, err := ioutil.ReadFile(args[0])
b, err := os.ReadFile(args[0])
if err != nil {
logrus.Fatal(err)
}
Expand Down
12 changes: 9 additions & 3 deletions cmd/script_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"regexp"

"github.com/gin-gonic/gin"
Expand All @@ -25,7 +25,7 @@ func NewScriptExec() *cobra.Command {
Use: "exec [ledger] [script]",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
b, err := ioutil.ReadFile(args[1])
b, err := os.ReadFile(args[1])
if err != nil {
logrus.Fatal(err)
}
Expand Down Expand Up @@ -82,7 +82,13 @@ func NewScriptExec() *cobra.Command {
fmt.Printf("ID: %d\r\n", result.Transaction.ID)
fmt.Println("Postings:")
for _, p := range result.Transaction.Postings {
fmt.Printf("\t Source: %s, Destination: %s, Amount: %d, Asset: %s\r\n", p.Source, p.Destination, p.Amount, p.Asset)
fmt.Printf(
"\t Source: %s, Destination: %s, Amount: %s, Asset: %s\r\n",
p.Source,
p.Destination,
p.Amount,
p.Asset,
)
}
if !viper.GetBool(previewFlag) {
fmt.Printf("Created transaction: http://%s/%s/transactions/%d\r\n",
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/jackc/pgconn v1.10.1
github.com/jackc/pgx/v4 v4.14.1
github.com/mattn/go-sqlite3 v1.14.9
github.com/numary/machine v1.2.0
github.com/numary/machine v1.2.1-0.20220811010804-0a87156a9a4b
github.com/ory/dockertest/v3 v3.8.1
github.com/pborman/uuid v1.2.1
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -40,14 +40,13 @@ require (
github.com/Shopify/sarama v1.32.0
github.com/ThreeDotsLabs/watermill v1.1.1
github.com/buger/jsonparser v1.1.1
github.com/gibson042/canonicaljson-go v1.0.3
github.com/go-redis/redis/v8 v8.11.4
github.com/go-redis/redismock/v8 v8.0.6
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/lib/pq v1.10.2
github.com/mitchellh/mapstructure v1.5.0
github.com/numary/go-libs v0.0.0-20220609103351-69aecd5d4097
github.com/numary/go-libs/sharedhealth v0.0.0-20220801152411-b600be8e0d85
github.com/numary/go-libs/sharedhealth v0.0.0-20220829123039-3eeb76619d81
github.com/numary/go-libs/sharedotlp v0.0.0-20220802090414-d0ae0613f325
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
github.com/psanford/memfs v0.0.0-20210214183328-a001468d78ef
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gibson042/canonicaljson-go v1.0.3 h1:EAyF8L74AWabkyUmrvEFHEt/AGFQeD6RfwbAuf0j1bI=
github.com/gibson042/canonicaljson-go v1.0.3/go.mod h1:DsLpJTThXyGNO+KZlI85C1/KDcImpP67k/RKVjcaEqo=
github.com/gin-contrib/cors v1.3.1 h1:doAsuITavI4IOcd0Y19U4B+O0dNWihRyX//nn4sEmgA=
github.com/gin-contrib/cors v1.3.1/go.mod h1:jjEJ4268OPZUcU7k9Pm653S7lXUGcqMADzFA61xsmDk=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
Expand Down Expand Up @@ -454,12 +452,12 @@ github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/numary/go-libs v0.0.0-20220609103351-69aecd5d4097 h1:50vHv20bk4REFNkbw2sOS3Fvzn7HzlzML0tY3QLxk3U=
github.com/numary/go-libs v0.0.0-20220609103351-69aecd5d4097/go.mod h1:7StJNTZ3QbU2uBWpOeryPaHD6xMYUN8AWXWTjP67kv0=
github.com/numary/go-libs/sharedhealth v0.0.0-20220801152411-b600be8e0d85 h1:+KA84QMomrNaoHrtrDIRbE4HkUrgu3JAsXcw8XF3OGQ=
github.com/numary/go-libs/sharedhealth v0.0.0-20220801152411-b600be8e0d85/go.mod h1:DzBUp4HCdWscgXmt8/5F/KlCSktv0OwgOwDfRdz5Hzo=
github.com/numary/go-libs/sharedhealth v0.0.0-20220829123039-3eeb76619d81 h1:VhHu7IUQZ6LOTY6a2QlWb5U3MofOV2yP+LGXywaTnP0=
github.com/numary/go-libs/sharedhealth v0.0.0-20220829123039-3eeb76619d81/go.mod h1:DzBUp4HCdWscgXmt8/5F/KlCSktv0OwgOwDfRdz5Hzo=
github.com/numary/go-libs/sharedotlp v0.0.0-20220802090414-d0ae0613f325 h1:5hbV1OF6A4CYuZYtMJsX3bcTmgtKdY3DsaIKKpCoqJw=
github.com/numary/go-libs/sharedotlp v0.0.0-20220802090414-d0ae0613f325/go.mod h1:4QEZTmjeQbNMjWd/pKADguTjxTvAuWgh+ZBWzJ7xDiI=
github.com/numary/machine v1.2.0 h1:Jiy8FMPCJb4Cep5nACXyIQFzVPHse+t2w9Jzzqc7Ojk=
github.com/numary/machine v1.2.0/go.mod h1:vK6ftGapdOvYjFxbRHFYKxzce4doaCpfk9Wqkhozkfw=
github.com/numary/machine v1.2.1-0.20220811010804-0a87156a9a4b h1:dw6XcO2+7gETGB9JnugRfTyXm5WVQSkzHjYn+AYvxSw=
github.com/numary/machine v1.2.1-0.20220811010804-0a87156a9a4b/go.mod h1:Urkud39TPaMxmSwOd6H3hCqob710Et/tcWSv0QjbyGo=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down
4 changes: 2 additions & 2 deletions pkg/analytics/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
"os"
"sync"
Expand Down Expand Up @@ -103,7 +103,7 @@ func EventuallyQueueNotEmpty[ITEM any](t *testing.T, queue *Queue[ITEM]) {
}

var emptyHttpResponse = &http.Response{
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
Body: io.NopCloser(bytes.NewReader([]byte{})),
StatusCode: http.StatusOK,
}

Expand Down
13 changes: 7 additions & 6 deletions pkg/api/controllers/account_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestGetAccounts(t *testing.T) {
{
Source: "world",
Destination: "alice",
Amount: 150,
Amount: core.NewMonetaryInt(150),
Asset: "USD",
},
},
Expand All @@ -43,7 +43,7 @@ func TestGetAccounts(t *testing.T) {
{
Source: "world",
Destination: "bob",
Amount: 100,
Amount: core.NewMonetaryInt(100),
Asset: "USD",
},
},
Expand Down Expand Up @@ -422,7 +422,7 @@ func TestGetAccount(t *testing.T) {
{
Source: "world",
Destination: "alice",
Amount: 100,
Amount: core.NewMonetaryInt(100),
Asset: "USD",
},
},
Expand All @@ -448,11 +448,12 @@ func TestGetAccount(t *testing.T) {
},
},
Balances: core.AssetsBalances{
"USD": 100,
"USD": core.NewMonetaryInt(100),
},
Volumes: core.AssetsVolumes{
"USD": {
Input: 100,
Input: core.NewMonetaryInt(100),
Output: core.NewMonetaryInt(0),
},
},
}, resp)
Expand Down Expand Up @@ -499,7 +500,7 @@ func TestPostAccountMetadata(t *testing.T) {
{
Source: "world",
Destination: "alice",
Amount: 100,
Amount: core.NewMonetaryInt(100),
Asset: "USD",
},
},
Expand Down
Loading

0 comments on commit bbd082a

Please sign in to comment.