From 2c56c12d7e6481dbb5842b4dd370a33f9aa5cb34 Mon Sep 17 00:00:00 2001 From: harry <53987565+h5law@users.noreply.github.com> Date: Mon, 23 Oct 2023 18:56:05 +0100 Subject: [PATCH 1/3] feat: seperate tests from go_develop (#89) --- Makefile | 5 ++++- go.mod | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c13061153..9873e1206 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,10 @@ go_mockgen: ## Use `mockgen` to generate mocks used for testing purposes of all go generate ./x/supplier/types/ .PHONY: go_develop -go_develop: proto_regen go_mockgen go_test ## Generate protos, mocks and run all tests +go_develop: proto_regen go_mockgen ## Generate protos and mocks + +.PHONY: go_develop_and_test +go_develop_and_test: go_develop go_test ## Generate protos, mocks and run all tests ############# ### TODOS ### diff --git a/go.mod b/go.mod index 3534e7fda..9c881afe5 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( cosmossdk.io/math v1.0.1 github.com/cometbft/cometbft v0.37.2 github.com/cometbft/cometbft-db v0.8.0 - github.com/cosmos/cosmos-proto v1.0.0-beta.2 github.com/cosmos/cosmos-sdk v0.47.3 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-go/v7 v7.1.0 @@ -23,7 +22,6 @@ require ( github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 golang.org/x/sync v0.3.0 - google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 google.golang.org/grpc v1.56.1 gopkg.in/yaml.v2 v2.4.0 ) @@ -68,6 +66,7 @@ require ( github.com/containerd/cgroups v1.1.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect + github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/iavl v0.20.0 // indirect @@ -266,6 +265,7 @@ require ( gonum.org/v1/gonum v0.11.0 // indirect google.golang.org/api v0.122.0 // indirect google.golang.org/appengine v1.6.7 // indirect + google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect From fc870347428a96fbfda66f1e92cd2253d3dc6b24 Mon Sep 17 00:00:00 2001 From: harry <53987565+h5law@users.noreply.github.com> Date: Mon, 23 Oct 2023 19:22:05 +0100 Subject: [PATCH 2/3] [E2E] Add Regression Testing for Send E2E Feature Test (#84) --- e2e/tests/init_test.go | 103 ++++++++++++++++++++++++++++++++++------- e2e/tests/node.go | 2 +- e2e/tests/send.feature | 7 ++- go.mod | 4 +- 4 files changed, 94 insertions(+), 22 deletions(-) diff --git a/e2e/tests/init_test.go b/e2e/tests/init_test.go index 0ab3be752..fe831a507 100644 --- a/e2e/tests/init_test.go +++ b/e2e/tests/init_test.go @@ -5,26 +5,37 @@ package e2e import ( "fmt" "regexp" + "strconv" "strings" "testing" + "time" "github.com/regen-network/gocuke" "github.com/stretchr/testify/require" ) -var addrRe *regexp.Regexp +var ( + addrRe *regexp.Regexp + amountRe *regexp.Regexp + accNameToAddrMap = make(map[string]string) + keyRingFlag = "--keyring-backend=test" +) func init() { - addrRe = regexp.MustCompile(`address:\s+(pokt1\w+)`) + addrRe = regexp.MustCompile(`address: (\S+)\s+name: (\S+)`) + amountRe = regexp.MustCompile(`amount: "(.+?)"\s+denom: upokt`) } type suite struct { gocuke.TestingT - pocketd *pocketdBin + pocketd *pocketdBin + scenarioState map[string]any // temporary state for each scenario } func (s *suite) Before() { s.pocketd = new(pocketdBin) + s.scenarioState = make(map[string]any) + s.buildAddrMap() } // TestFeatures runs the e2e tests specified in any .features files in this directory @@ -56,17 +67,15 @@ func (s *suite) TheUserShouldBeAbleToSeeStandardOutputContaining(arg1 string) { } } -func (s *suite) TheUserSendsUpoktToAnotherAddress(amount int64) { - addrs := s.getAddresses() +func (s *suite) TheUserSendsUpoktFromAccountToAccount(amount int64, accName1, accName2 string) { args := []string{ "tx", "bank", "send", - addrs[0], - addrs[1], + accNameToAddrMap[accName1], + accNameToAddrMap[accName2], fmt.Sprintf("%dupokt", amount), - "--keyring-backend", - "test", + keyRingFlag, "-y", } res, err := s.pocketd.RunCommandOnHost("", args...) @@ -76,20 +85,78 @@ func (s *suite) TheUserSendsUpoktToAnotherAddress(amount int64) { s.pocketd.result = res } -func (s *suite) getAddresses() [2]string { - var strs [2]string +func (s *suite) TheAccountHasABalanceGreaterThanUpokt(accName string, amount int64) { + bal := s.getAccBalance(accName) + if int64(bal) < amount { + s.Fatalf("account %s does not have enough upokt: %d < %d", accName, bal, amount) + } + s.scenarioState[accName] = bal // save the balance for later +} + +func (s *suite) AnAccountExistsFor(accName string) { + bal := s.getAccBalance(accName) + s.scenarioState[accName] = bal // save the balance for later +} + +func (s *suite) TheAccountBalanceOfShouldBeUpoktThanBefore(accName string, amount int64, condition string) { + prev, ok := s.scenarioState[accName] + if !ok { + s.Fatalf("no previous balance found for %s", accName) + } + + bal := s.getAccBalance(accName) + switch condition { + case "more": + if bal <= prev.(int) { + s.Fatalf("account %s expected to have more upokt but: %d <= %d", accName, bal, prev) + } + case "less": + if bal >= prev.(int) { + s.Fatalf("account %s expected to have less upokt but: %d >= %d", accName, bal, prev) + } + default: + s.Fatalf("unknown condition %s", condition) + } +} + +func (s *suite) TheUserShouldWaitForSeconds(dur int64) { + time.Sleep(time.Duration(dur) * time.Second) +} + +func (s *suite) buildAddrMap() { + s.Helper() res, err := s.pocketd.RunCommand( - "keys", "list", "--keyring-backend", "test", + "keys", "list", keyRingFlag, ) if err != nil { s.Fatalf("error getting keys: %s", err) } matches := addrRe.FindAllStringSubmatch(res.Stdout, -1) - if len(matches) >= 2 { - strs[0] = matches[0][1] - strs[1] = matches[len(matches)-1][1] - } else { - s.Fatalf("could not find two addresses in output: %s", res.Stdout) + for _, match := range matches { + name := match[2] + address := match[1] + accNameToAddrMap[name] = address + } +} + +func (s *suite) getAccBalance(accName string) int { + s.Helper() + args := []string{ + "query", + "bank", + "balances", + accNameToAddrMap[accName], + } + res, err := s.pocketd.RunCommandOnHost("", args...) + if err != nil { + s.Fatalf("error getting balance: %s", err) + } + s.pocketd.result = res + match := amountRe.FindStringSubmatch(res.Stdout) + if len(match) < 2 { + s.Fatalf("no balance found for %s", accName) } - return strs + found, err := strconv.Atoi(match[1]) + require.NoError(s, err) + return found } diff --git a/e2e/tests/node.go b/e2e/tests/node.go index 4a025cae5..ba0e3b46b 100644 --- a/e2e/tests/node.go +++ b/e2e/tests/node.go @@ -24,7 +24,7 @@ func init() { defaultRPCURL = fmt.Sprintf("tcp://%s:%d", defaultRPCHost, defaultRPCPort) } if defaultHome == "" { - defaultHome = "./localnet/pocketd" + defaultHome = "../../localnet/pocketd" } } diff --git a/e2e/tests/send.feature b/e2e/tests/send.feature index 1e2bdf2f8..dc5fc4504 100644 --- a/e2e/tests/send.feature +++ b/e2e/tests/send.feature @@ -2,7 +2,12 @@ Feature: Tx Namespace Scenario: User can send uPOKT Given the user has the pocketd binary installed - When the user sends 10000 uPOKT to another address + And the account "app1" has a balance greater than "1000" uPOKT + And an account exists for "app2" + When the user sends "1000" uPOKT from account "app1" to account "app2" Then the user should be able to see standard output containing "txhash:" And the user should be able to see standard output containing "code: 0" And the pocketd binary should exit without error + And the user should wait for "5" seconds + And the account balance of "app1" should be "1000" uPOKT "less" than before + And the account balance of "app2" should be "1000" uPOKT "more" than before diff --git a/go.mod b/go.mod index 9c881afe5..3534e7fda 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( cosmossdk.io/math v1.0.1 github.com/cometbft/cometbft v0.37.2 github.com/cometbft/cometbft-db v0.8.0 + github.com/cosmos/cosmos-proto v1.0.0-beta.2 github.com/cosmos/cosmos-sdk v0.47.3 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-go/v7 v7.1.0 @@ -22,6 +23,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 golang.org/x/sync v0.3.0 + google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 google.golang.org/grpc v1.56.1 gopkg.in/yaml.v2 v2.4.0 ) @@ -66,7 +68,6 @@ require ( github.com/containerd/cgroups v1.1.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect - github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/iavl v0.20.0 // indirect @@ -265,7 +266,6 @@ require ( gonum.org/v1/gonum v0.11.0 // indirect google.golang.org/api v0.122.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect From bc385104ba2ae11e8a2f1aa2aa85320d488ae745 Mon Sep 17 00:00:00 2001 From: harry <53987565+h5law@users.noreply.github.com> Date: Mon, 23 Oct 2023 22:52:33 +0100 Subject: [PATCH 3/3] chore: enforce go standard interface implementation registration (#87) --- .github/workflows/reviewdog.yml | 16 +++++++++++++++- e2e/tests/node.go | 2 +- pkg/observable/channel/observable.go | 2 +- pkg/observable/channel/observer.go | 2 +- pkg/relayer/proxy/proxy.go | 2 +- .../types/message_delegate_to_gateway.go | 2 +- x/application/types/message_stake_application.go | 2 +- .../types/message_undelegate_from_gateway.go | 2 +- .../types/message_unstake_application.go | 2 +- x/gateway/types/message_stake_gateway.go | 2 +- x/gateway/types/message_unstake_gateway.go | 2 +- x/supplier/types/message_create_claim.go | 2 +- x/supplier/types/message_stake_supplier.go | 2 +- x/supplier/types/message_submit_proof.go | 2 +- x/supplier/types/message_unstake_supplier.go | 2 +- 15 files changed, 29 insertions(+), 15 deletions(-) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 5a79d3709..62afe323e 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -20,6 +20,20 @@ jobs: fail_on_error: true pattern: TODO_IN_THIS_ + check_non_standard_interface_implementations: + name: Check for non-standard interface implementation statements + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pokt-network/action-fail-on-found@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + level: error + fail_on_error: true + pattern: var _ .* = &.*{} + ignore: .github,.git + # More info: https://github.com/reviewdog/action-misspell check_misspell: name: Check misspelling @@ -31,4 +45,4 @@ jobs: github_token: ${{ secrets.github_token }} reporter: github-check level: warning - locale: "US" \ No newline at end of file + locale: "US" diff --git a/e2e/tests/node.go b/e2e/tests/node.go index ba0e3b46b..4e34fa827 100644 --- a/e2e/tests/node.go +++ b/e2e/tests/node.go @@ -42,7 +42,7 @@ type PocketClient interface { } // Ensure that pocketdBin struct fulfills PocketClient -var _ PocketClient = &pocketdBin{} +var _ PocketClient = (*pocketdBin)(nil) // pocketdBin holds the reults of the last command that was run type pocketdBin struct { diff --git a/pkg/observable/channel/observable.go b/pkg/observable/channel/observable.go index 8e17ad9fb..26958a75b 100644 --- a/pkg/observable/channel/observable.go +++ b/pkg/observable/channel/observable.go @@ -13,7 +13,7 @@ import ( // defaultSubscribeBufferSize is the buffer size of a observable's publish channel. const defaultPublishBufferSize = 50 -var _ observable.Observable[any] = &channelObservable[any]{} +var _ observable.Observable[any] = (*channelObservable[any])(nil) // option is a function which receives and can modify the channelObservable state. type option[V any] func(obs *channelObservable[V]) diff --git a/pkg/observable/channel/observer.go b/pkg/observable/channel/observer.go index f90bec563..394a6bdbb 100644 --- a/pkg/observable/channel/observer.go +++ b/pkg/observable/channel/observer.go @@ -24,7 +24,7 @@ const ( sendRetryInterval = 100 * time.Millisecond ) -var _ observable.Observer[any] = &channelObserver[any]{} +var _ observable.Observer[any] = (*channelObserver[any])(nil) // channelObserver implements the observable.Observer interface. type channelObserver[V any] struct { diff --git a/pkg/relayer/proxy/proxy.go b/pkg/relayer/proxy/proxy.go index f3d53f5e0..f626f184f 100644 --- a/pkg/relayer/proxy/proxy.go +++ b/pkg/relayer/proxy/proxy.go @@ -16,7 +16,7 @@ import ( suppliertypes "pocket/x/supplier/types" ) -var _ RelayerProxy = &relayerProxy{} +var _ RelayerProxy = (*relayerProxy)(nil) type relayerProxy struct { // keyName is the supplier's key name in the Cosmos's keybase. It is used along with the keyring to diff --git a/x/application/types/message_delegate_to_gateway.go b/x/application/types/message_delegate_to_gateway.go index d162c61bf..232564310 100644 --- a/x/application/types/message_delegate_to_gateway.go +++ b/x/application/types/message_delegate_to_gateway.go @@ -7,7 +7,7 @@ import ( const TypeMsgDelegateToGateway = "delegate_to_gateway" -var _ sdk.Msg = &MsgDelegateToGateway{} +var _ sdk.Msg = (*MsgDelegateToGateway)(nil) func NewMsgDelegateToGateway(address string) *MsgDelegateToGateway { return &MsgDelegateToGateway{ diff --git a/x/application/types/message_stake_application.go b/x/application/types/message_stake_application.go index 93532f2bd..219a65701 100644 --- a/x/application/types/message_stake_application.go +++ b/x/application/types/message_stake_application.go @@ -8,7 +8,7 @@ import ( const TypeMsgStakeApplication = "stake_application" -var _ sdk.Msg = &MsgStakeApplication{} +var _ sdk.Msg = (*MsgStakeApplication)(nil) func NewMsgStakeApplication( address string, diff --git a/x/application/types/message_undelegate_from_gateway.go b/x/application/types/message_undelegate_from_gateway.go index 2cca7962c..240605383 100644 --- a/x/application/types/message_undelegate_from_gateway.go +++ b/x/application/types/message_undelegate_from_gateway.go @@ -7,7 +7,7 @@ import ( const TypeMsgUndelegateFromGateway = "undelegate_from_gateway" -var _ sdk.Msg = &MsgUndelegateFromGateway{} +var _ sdk.Msg = (*MsgUndelegateFromGateway)(nil) func NewMsgUndelegateFromGateway(address string) *MsgUndelegateFromGateway { return &MsgUndelegateFromGateway{ diff --git a/x/application/types/message_unstake_application.go b/x/application/types/message_unstake_application.go index 1f4051f52..010bae551 100644 --- a/x/application/types/message_unstake_application.go +++ b/x/application/types/message_unstake_application.go @@ -7,7 +7,7 @@ import ( const TypeMsgUnstakeApplication = "unstake_application" -var _ sdk.Msg = &MsgUnstakeApplication{} +var _ sdk.Msg = (*MsgUnstakeApplication)(nil) func NewMsgUnstakeApplication(address string) *MsgUnstakeApplication { return &MsgUnstakeApplication{ diff --git a/x/gateway/types/message_stake_gateway.go b/x/gateway/types/message_stake_gateway.go index c86375288..70811076c 100644 --- a/x/gateway/types/message_stake_gateway.go +++ b/x/gateway/types/message_stake_gateway.go @@ -8,7 +8,7 @@ import ( const TypeMsgStakeGateway = "stake_gateway" -var _ sdk.Msg = &MsgStakeGateway{} +var _ sdk.Msg = (*MsgStakeGateway)(nil) func NewMsgStakeGateway(address string, stake types.Coin) *MsgStakeGateway { return &MsgStakeGateway{ diff --git a/x/gateway/types/message_unstake_gateway.go b/x/gateway/types/message_unstake_gateway.go index cb60f2009..23bf5f97a 100644 --- a/x/gateway/types/message_unstake_gateway.go +++ b/x/gateway/types/message_unstake_gateway.go @@ -7,7 +7,7 @@ import ( const TypeMsgUnstakeGateway = "unstake_gateway" -var _ sdk.Msg = &MsgUnstakeGateway{} +var _ sdk.Msg = (*MsgUnstakeGateway)(nil) func NewMsgUnstakeGateway(address string) *MsgUnstakeGateway { return &MsgUnstakeGateway{ diff --git a/x/supplier/types/message_create_claim.go b/x/supplier/types/message_create_claim.go index 98acf0c72..4bcfada3b 100644 --- a/x/supplier/types/message_create_claim.go +++ b/x/supplier/types/message_create_claim.go @@ -9,7 +9,7 @@ import ( const TypeMsgCreateClaim = "create_claim" -var _ sdk.Msg = &MsgCreateClaim{} +var _ sdk.Msg = (*MsgCreateClaim)(nil) func NewMsgCreateClaim(supplierAddress string, sessionHeader *sessiontypes.SessionHeader, rootHash []byte) *MsgCreateClaim { return &MsgCreateClaim{ diff --git a/x/supplier/types/message_stake_supplier.go b/x/supplier/types/message_stake_supplier.go index a441ce6bc..9d4ce5cdc 100644 --- a/x/supplier/types/message_stake_supplier.go +++ b/x/supplier/types/message_stake_supplier.go @@ -8,7 +8,7 @@ import ( const TypeMsgStakeSupplier = "stake_supplier" -var _ sdk.Msg = &MsgStakeSupplier{} +var _ sdk.Msg = (*MsgStakeSupplier)(nil) func NewMsgStakeSupplier( address string, diff --git a/x/supplier/types/message_submit_proof.go b/x/supplier/types/message_submit_proof.go index ee2dec47a..32faa796b 100644 --- a/x/supplier/types/message_submit_proof.go +++ b/x/supplier/types/message_submit_proof.go @@ -9,7 +9,7 @@ import ( const TypeMsgSubmitProof = "submit_proof" -var _ sdk.Msg = &MsgSubmitProof{} +var _ sdk.Msg = (*MsgSubmitProof)(nil) func NewMsgSubmitProof(supplierAddress string, sessionHeader *sessiontypes.SessionHeader, proof []byte) *MsgSubmitProof { return &MsgSubmitProof{ diff --git a/x/supplier/types/message_unstake_supplier.go b/x/supplier/types/message_unstake_supplier.go index eec8ede80..884c21c36 100644 --- a/x/supplier/types/message_unstake_supplier.go +++ b/x/supplier/types/message_unstake_supplier.go @@ -7,7 +7,7 @@ import ( const TypeMsgUnstakeSupplier = "unstake_supplier" -var _ sdk.Msg = &MsgUnstakeSupplier{} +var _ sdk.Msg = (*MsgUnstakeSupplier)(nil) func NewMsgUnstakeSupplier(address string) *MsgUnstakeSupplier { return &MsgUnstakeSupplier{