Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get cognitarium address on new dataverse client #18

Merged
merged 8 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ mock: ## Generate all the mocks (for tests)
@mockgen -source=auth/proxy.go -package testutil -destination testutil/auth_mocks.go
@mockgen -source=dataverse/client.go -package testutil -destination testutil/dataverse_mocks.go
@mockgen -source=credential/parser.go -package testutil -destination testutil/credential_mocks.go
@mockgen -package testutil -destination testutil/dataverse_client_mocks.go -mock_names QueryClient=MockDataverseQueryClient github.com/axone-protocol/axone-contract-schema/go/dataverse-schema/v5 QueryClient
@mockgen -package testutil -destination testutil/cognitarium_client_mocks.go -mock_names QueryClient=MockCognitariumQueryClient github.com/axone-protocol/axone-contract-schema/go/cognitarium-schema/v5 QueryClient

## Help:
.PHONY: help
Expand Down
57 changes: 55 additions & 2 deletions dataverse/client.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@
package dataverse

import "context"
import (
"context"
"fmt"

dvschema "github.com/axone-protocol/axone-contract-schema/go/dataverse-schema/v5"
"google.golang.org/grpc"
)

type Client interface {
GetGovAddr(context.Context, string) (string, error)
GetResourceGovAddr(context.Context, string) (string, error)
ExecGov(context.Context, string, string) (interface{}, error)
}

type client struct {
dataverseClient dvschema.QueryClient
cognitariumAddr string
}

func NewDataverseClient(ctx context.Context, dataverseClient dvschema.QueryClient) (Client, error) {
cognitariumAddr, err := getCognitariumAddr(ctx, dataverseClient)
if err != nil {
return nil, fmt.Errorf("failed to get cognitarium address: %w", err)
}

return &client{
dataverseClient,
cognitariumAddr,
}, nil
}

func NewClient(ctx context.Context,
grpcAddr, contractAddr string,
opts ...grpc.DialOption,
) (Client, error) {
dataverseClient, err := dvschema.NewQueryClient(grpcAddr, contractAddr, opts...)
if err != nil {
return nil, fmt.Errorf("failed to create dataverse client: %w", err)

Check warning on line 39 in dataverse/client.go

View check run for this annotation

Codecov / codecov/patch

dataverse/client.go#L36-L39

Added lines #L36 - L39 were not covered by tests
}

return NewDataverseClient(ctx, dataverseClient)

Check warning on line 42 in dataverse/client.go

View check run for this annotation

Codecov / codecov/patch

dataverse/client.go#L42

Added line #L42 was not covered by tests
}
bdeneux marked this conversation as resolved.
Show resolved Hide resolved

func (c *client) GetResourceGovAddr(_ context.Context, _ string) (string, error) {
panic("not implemented")

Check warning on line 46 in dataverse/client.go

View check run for this annotation

Codecov / codecov/patch

dataverse/client.go#L45-L46

Added lines #L45 - L46 were not covered by tests
bdeneux marked this conversation as resolved.
Show resolved Hide resolved
}

func (c *client) ExecGov(_ context.Context, _ string, _ string) (interface{}, error) {
panic("not implemented")

Check warning on line 50 in dataverse/client.go

View check run for this annotation

Codecov / codecov/patch

dataverse/client.go#L49-L50

Added lines #L49 - L50 were not covered by tests
bdeneux marked this conversation as resolved.
Show resolved Hide resolved
}

func getCognitariumAddr(ctx context.Context, dvClient dvschema.QueryClient) (string, error) {
query := dvschema.QueryMsg_Dataverse{}
resp, err := dvClient.Dataverse(ctx, &query)
if err != nil {
return "", err
}

return string(resp.TriplestoreAddress), nil
}
68 changes: 68 additions & 0 deletions dataverse/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package dataverse_test

import (
"context"
"fmt"
"testing"

schema "github.com/axone-protocol/axone-contract-schema/go/dataverse-schema/v5"
"github.com/axone-protocol/axone-sdk/dataverse"
"github.com/axone-protocol/axone-sdk/testutil"
. "github.com/smartystreets/goconvey/convey"
"go.uber.org/mock/gomock"
)

func TestClient_NewDataverseClient(t *testing.T) {
tests := []struct {
name string
returnedErr error
wantErr error
wantAddr string
}{
{
name: "receive an cognitarium address",
returnedErr: nil,
wantErr: nil,
wantAddr: "addr",
},
{
name: "receive an error",
returnedErr: fmt.Errorf("error"),
wantErr: fmt.Errorf("failed to get cognitarium address: %w", fmt.Errorf("error")),
wantAddr: "",
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Convey("Given a mocked dataverse client", t, func() {
controller := gomock.NewController(t)
defer controller.Finish()

mockClient := testutil.NewMockDataverseQueryClient(controller)
mockClient.EXPECT().
Dataverse(gomock.Any(), gomock.Any()).
Return(
&schema.DataverseResponse{
TriplestoreAddress: schema.Addr(test.wantAddr),
},
test.returnedErr,
).
Times(1)

Convey("When Client is created", func() {
client, err := dataverse.NewDataverseClient(context.Background(), mockClient)

Convey("Then the client should be created if no error on dataverse client", func() {
So(err, ShouldEqual, test.wantErr)
if test.wantErr == nil {
So(client, ShouldNotBeNil)
} else {
So(client, ShouldBeNil)
}
})
})
})
})
}
}
39 changes: 26 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module github.com/axone-protocol/axone-sdk

go 1.21
go 1.22.5

require (
github.com/axone-protocol/axone-contract-schema/go/cognitarium-schema/v5 v5.0.0-20240826124342-6e6abdf73c9a
github.com/axone-protocol/axone-contract-schema/go/dataverse-schema/v5 v5.0.0-20240826124342-6e6abdf73c9a
github.com/axone-protocol/axoned/v9 v9.0.0
github.com/btcsuite/btcd v0.22.0-beta
github.com/cosmos/cosmos-sdk v0.50.9
Expand All @@ -25,16 +27,20 @@ require (
cosmossdk.io/core v0.11.1 // indirect
cosmossdk.io/depinject v1.0.0 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/log v1.4.1 // indirect
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/store v1.1.0 // indirect
cosmossdk.io/x/tx v0.13.4 // indirect
cosmossdk.io/x/upgrade v0.1.4 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/CosmWasm/wasmd v0.53.0 // indirect
github.com/CosmWasm/wasmvm/v2 v2.1.2 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/VictoriaMetrics/fastcache v1.5.7 // indirect
// indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
Expand All @@ -50,15 +56,17 @@ require (
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft v0.38.10 // indirect
github.com/cometbft/cometbft v0.38.11 // indirect
github.com/cometbft/cometbft-db v0.9.1 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-db v1.0.2 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.5.0 // indirect
github.com/cosmos/gogoproto v1.7.0 // indirect
github.com/cosmos/iavl v1.2.0 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.1 // indirect
github.com/cosmos/ibc-go/v8 v8.4.0 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
Expand All @@ -67,6 +75,7 @@ require (
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dustinxie/ecc v0.0.0-20210511000915-959544187564 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
Expand Down Expand Up @@ -105,7 +114,7 @@ require (
github.com/huandu/skiplist v1.2.0 // indirect
github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230427134832-0c9969493bd3 // indirect
github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3 // indirect
github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230501135648-a9a7ad029347 // indirect
github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230501135648-a9a7ad029347
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20230427134832-0c9969493bd3 // indirect
github.com/hyperledger/aries-framework-go/spi v0.0.0-20230427134832-0c9969493bd3 // indirect
github.com/hyperledger/ursa-wrapper-go v0.3.1 // indirect
Expand All @@ -117,7 +126,7 @@ require (
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/kilic/bls12-381 v0.1.1-0.20210503002446-7b7597926c69 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/linxGnu/grocksdb v1.8.14 // indirect
Expand All @@ -136,17 +145,19 @@ require (
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multihash v0.0.13 // indirect
github.com/multiformats/go-varint v0.0.5 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/pquerna/cachecontrol v0.1.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_golang v1.20.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.52.2 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.9.0 // indirect
Expand All @@ -155,12 +166,13 @@ require (
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/samber/lo v1.39.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shamaton/msgpack/v2 v2.2.0 // indirect
github.com/smarty/assertions v1.15.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
Expand All @@ -181,15 +193,16 @@ require (
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect
google.golang.org/grpc v1.64.1 // indirect
google.golang.org/grpc v1.64.1
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
Expand Down
Loading
Loading