From 68cd699e22c2647b6626366b318cbb44ac8a1261 Mon Sep 17 00:00:00 2001 From: akhilkumarpilli Date: Mon, 4 Nov 2024 21:48:18 +0530 Subject: [PATCH 1/6] test(accounts): fix integration tests and update ci --- .github/workflows/test.yml | 4 ++++ scripts/build/testing.mk | 5 ++++- tests/Makefile | 3 +++ .../integration/accounts/base_account_test.go | 22 ++++++++++++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b1762032c33b..ac854b5c0b09 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -112,6 +112,10 @@ jobs: with: name: "${{ github.sha }}-integration-coverage" path: ./tests/integration-profile.out + - name: integration tests v1 + if: env.GIT_DIFF + run: | + make test-integration-v1 test-system: # v2 system tests are in v2-test.yml runs-on: ubuntu-latest diff --git a/scripts/build/testing.mk b/scripts/build/testing.mk index 2e58da7a4284..5d98af45a619 100644 --- a/scripts/build/testing.mk +++ b/scripts/build/testing.mk @@ -17,8 +17,11 @@ test-integration: #? test-integration-cov: Run `make -C tests test-integration-cov` test-integration-cov: $(MAKE) -C tests test-integration-cov +#? test-integration-v1: Run `make -C tests test-integration-v1` +test-integration-v1: + $(MAKE) -C tests test-integration-v1 #? test-all: Run all test -test-all: test-unit test-integration test-ledger-mock test-race +test-all: test-unit test-integration test-integration-v1 test-ledger-mock test-race .PHONY: test-system test-system: build diff --git a/tests/Makefile b/tests/Makefile index 04266002f7e8..5862f66119d7 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,5 +1,8 @@ test-integration: go test ./integration/... -timeout 30m +test-integration-v1: + go test -tags='app_v1' ./integration/... -timeout 30m + test-integration-cov: go test ./integration/... -timeout 30m -coverpkg=../... -coverprofile=integration-profile.out -covermode=atomic diff --git a/tests/integration/accounts/base_account_test.go b/tests/integration/accounts/base_account_test.go index bfaee8bbb357..aede4b0c8ce7 100644 --- a/tests/integration/accounts/base_account_test.go +++ b/tests/integration/accounts/base_account_test.go @@ -9,18 +9,25 @@ import ( gogoproto "github.com/cosmos/gogoproto/proto" gogoany "github.com/cosmos/gogoproto/types/any" + "cosmossdk.io/math" "cosmossdk.io/simapp" baseaccountv1 "cosmossdk.io/x/accounts/defaults/base/v1" "cosmossdk.io/x/bank/testutil" banktypes "cosmossdk.io/x/bank/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" ) +var ( + privKey = secp256k1.GenPrivKey() + accCreator = []byte("creator") +) + func TestBaseAccount(t *testing.T) { app := setupApp(t) ak := app.AccountsKeeper @@ -41,7 +48,7 @@ func TestBaseAccount(t *testing.T) { msg := &banktypes.MsgSend{ FromAddress: bechify(t, app, baseAccountAddr), ToAddress: bechify(t, app, []byte("random-addr")), - Amount: coins(t, "100stake"), + Amount: sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(100))), } sendTx(t, ctx, app, baseAccountAddr, msg) } @@ -95,3 +102,16 @@ func toAnyPb(t *testing.T, pm gogoproto.Message) *codectypes.Any { require.NoError(t, err) return pb } + +func coins(t *testing.T, s string) sdk.Coins { + t.Helper() + coins, err := sdk.ParseCoinsNormalized(s) + require.NoError(t, err) + return coins +} + +func setupApp(t *testing.T) *simapp.SimApp { + t.Helper() + app := simapp.Setup(t, false) + return app +} From efc6ac8cb2eb2b0a759b2a340c48c86703a1435c Mon Sep 17 00:00:00 2001 From: akhilkumarpilli Date: Mon, 4 Nov 2024 21:51:41 +0530 Subject: [PATCH 2/6] revert change --- tests/integration/accounts/base_account_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/accounts/base_account_test.go b/tests/integration/accounts/base_account_test.go index aede4b0c8ce7..a515d3b6b784 100644 --- a/tests/integration/accounts/base_account_test.go +++ b/tests/integration/accounts/base_account_test.go @@ -9,7 +9,6 @@ import ( gogoproto "github.com/cosmos/gogoproto/proto" gogoany "github.com/cosmos/gogoproto/types/any" - "cosmossdk.io/math" "cosmossdk.io/simapp" baseaccountv1 "cosmossdk.io/x/accounts/defaults/base/v1" "cosmossdk.io/x/bank/testutil" @@ -48,7 +47,7 @@ func TestBaseAccount(t *testing.T) { msg := &banktypes.MsgSend{ FromAddress: bechify(t, app, baseAccountAddr), ToAddress: bechify(t, app, []byte("random-addr")), - Amount: sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(100))), + Amount: coins(t, "100stake"), } sendTx(t, ctx, app, baseAccountAddr, msg) } From 5b52d2a679aa279bda6bb27341436af084e1fe46 Mon Sep 17 00:00:00 2001 From: akhilkumarpilli Date: Tue, 5 Nov 2024 14:53:02 +0530 Subject: [PATCH 3/6] revert ci changes and fix one file test --- .github/workflows/test.yml | 35 ------------------- scripts/build/testing.mk | 5 +-- simapp/app_di.go | 6 ++++ tests/Makefile | 3 -- .../integration/accounts/base_account_test.go | 2 -- tests/integration/accounts/wiring_test.go | 2 -- .../testing/account_abstraction/minimal.go | 4 +++ x/accounts/testing/counter/counter.go | 4 +++ 8 files changed, 15 insertions(+), 46 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ac854b5c0b09..2a215b89747a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -112,10 +112,6 @@ jobs: with: name: "${{ github.sha }}-integration-coverage" path: ./tests/integration-profile.out - - name: integration tests v1 - if: env.GIT_DIFF - run: | - make test-integration-v1 test-system: # v2 system tests are in v2-test.yml runs-on: ubuntu-latest @@ -608,37 +604,6 @@ jobs: with: projectBaseDir: collections/ - test-collections-protocodec: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version: "1.23" - check-latest: true - cache: true - cache-dependency-path: collections/protocodec/go.sum - - uses: technote-space/get-diff-action@v6.1.2 - id: git_diff - with: - PATTERNS: | - collections/protocodec/**/*.go - collections/protocodec/go.mod - collections/protocodec/go.sum - - name: tests - if: env.GIT_DIFF - run: | - cd collections/protocodec - go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock' ./... - - name: sonarcloud - if: ${{ env.GIT_DIFF && !github.event.pull_request.draft && env.SONAR_TOKEN != null }} - uses: SonarSource/sonarcloud-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - with: - projectBaseDir: collections/protocodec - test-orm: runs-on: ubuntu-latest steps: diff --git a/scripts/build/testing.mk b/scripts/build/testing.mk index 5d98af45a619..2e58da7a4284 100644 --- a/scripts/build/testing.mk +++ b/scripts/build/testing.mk @@ -17,11 +17,8 @@ test-integration: #? test-integration-cov: Run `make -C tests test-integration-cov` test-integration-cov: $(MAKE) -C tests test-integration-cov -#? test-integration-v1: Run `make -C tests test-integration-v1` -test-integration-v1: - $(MAKE) -C tests test-integration-v1 #? test-all: Run all test -test-all: test-unit test-integration test-integration-v1 test-ledger-mock test-race +test-all: test-unit test-integration test-ledger-mock test-race .PHONY: test-system test-system: build diff --git a/simapp/app_di.go b/simapp/app_di.go index 0704cbdc38ca..3cd4aa6e717b 100644 --- a/simapp/app_di.go +++ b/simapp/app_di.go @@ -18,6 +18,8 @@ import ( basedepinject "cosmossdk.io/x/accounts/defaults/base/depinject" lockupdepinject "cosmossdk.io/x/accounts/defaults/lockup/depinject" multisigdepinject "cosmossdk.io/x/accounts/defaults/multisig/depinject" + "cosmossdk.io/x/accounts/testing/account_abstraction" + "cosmossdk.io/x/accounts/testing/counter" bankkeeper "cosmossdk.io/x/bank/keeper" circuitkeeper "cosmossdk.io/x/circuit/keeper" consensuskeeper "cosmossdk.io/x/consensus/keeper" @@ -180,6 +182,10 @@ func NewSimApp( // return fmt.Errorf("invalid pub key size") // } // }) + + // TESTING: do not add below account types + counter.ProvideAccount, + account_abstraction.ProvideAccount, ), ) ) diff --git a/tests/Makefile b/tests/Makefile index 5862f66119d7..04266002f7e8 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,8 +1,5 @@ test-integration: go test ./integration/... -timeout 30m -test-integration-v1: - go test -tags='app_v1' ./integration/... -timeout 30m - test-integration-cov: go test ./integration/... -timeout 30m -coverpkg=../... -coverprofile=integration-profile.out -covermode=atomic diff --git a/tests/integration/accounts/base_account_test.go b/tests/integration/accounts/base_account_test.go index a515d3b6b784..367f099984d4 100644 --- a/tests/integration/accounts/base_account_test.go +++ b/tests/integration/accounts/base_account_test.go @@ -1,5 +1,3 @@ -//go:build app_v1 - package accounts import ( diff --git a/tests/integration/accounts/wiring_test.go b/tests/integration/accounts/wiring_test.go index 86e86779408b..466bfbc2b765 100644 --- a/tests/integration/accounts/wiring_test.go +++ b/tests/integration/accounts/wiring_test.go @@ -1,5 +1,3 @@ -//go:build app_v1 - package accounts import ( diff --git a/x/accounts/testing/account_abstraction/minimal.go b/x/accounts/testing/account_abstraction/minimal.go index b450f0016cc8..20cf788ac775 100644 --- a/x/accounts/testing/account_abstraction/minimal.go +++ b/x/accounts/testing/account_abstraction/minimal.go @@ -74,3 +74,7 @@ func (a MinimalAbstractedAccount) RegisterExecuteHandlers(builder *accountstd.Ex func (a MinimalAbstractedAccount) RegisterQueryHandlers(builder *accountstd.QueryBuilder) { accountstd.RegisterQueryHandler(builder, a.QueryAuthenticateMethods) // implements account_abstraction } + +func ProvideAccount() accountstd.DepinjectAccount { + return accountstd.DIAccount("aa_minimal", NewMinimalAbstractedAccount) +} diff --git a/x/accounts/testing/counter/counter.go b/x/accounts/testing/counter/counter.go index 33ed5128f62b..b1f8397dc960 100644 --- a/x/accounts/testing/counter/counter.go +++ b/x/accounts/testing/counter/counter.go @@ -149,3 +149,7 @@ func (a Account) RegisterExecuteHandlers(builder *accountstd.ExecuteBuilder) { func (a Account) RegisterQueryHandlers(builder *accountstd.QueryBuilder) { accountstd.RegisterQueryHandler(builder, a.QueryCounter) } + +func ProvideAccount() accountstd.DepinjectAccount { + return accountstd.DIAccount("counter", NewAccount) +} From 093f4dc51b78d7b16708f2b7a43a2a095d3ff341 Mon Sep 17 00:00:00 2001 From: akhilkumarpilli Date: Tue, 5 Nov 2024 14:55:11 +0530 Subject: [PATCH 4/6] revert change --- .github/workflows/test.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a215b89747a..b1762032c33b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -604,6 +604,37 @@ jobs: with: projectBaseDir: collections/ + test-collections-protocodec: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: "1.23" + check-latest: true + cache: true + cache-dependency-path: collections/protocodec/go.sum + - uses: technote-space/get-diff-action@v6.1.2 + id: git_diff + with: + PATTERNS: | + collections/protocodec/**/*.go + collections/protocodec/go.mod + collections/protocodec/go.sum + - name: tests + if: env.GIT_DIFF + run: | + cd collections/protocodec + go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock' ./... + - name: sonarcloud + if: ${{ env.GIT_DIFF && !github.event.pull_request.draft && env.SONAR_TOKEN != null }} + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + projectBaseDir: collections/protocodec + test-orm: runs-on: ubuntu-latest steps: From eeb9814d9ac8ec40b9fbaf62475fea54760a9094 Mon Sep 17 00:00:00 2001 From: akhilkumarpilli Date: Mon, 11 Nov 2024 18:28:30 +0530 Subject: [PATCH 5/6] fix baseaccount test --- simapp/app_di.go | 17 +++++++++-------- x/validate/depinject.go | 17 +++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/simapp/app_di.go b/simapp/app_di.go index 02a8ae35b56c..6e8f8d4f63ee 100644 --- a/simapp/app_di.go +++ b/simapp/app_di.go @@ -305,14 +305,15 @@ func (app *SimApp) setCustomAnteHandler() { anteHandler, err := NewAnteHandler( HandlerOptions{ ante.HandlerOptions{ - AccountKeeper: app.AuthKeeper, - BankKeeper: app.BankKeeper, - ConsensusKeeper: app.ConsensusParamsKeeper, - SignModeHandler: app.txConfig.SignModeHandler(), - FeegrantKeeper: app.FeeGrantKeeper, - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - UnorderedTxManager: app.UnorderedTxManager, - Environment: app.AuthKeeper.Environment, + AccountKeeper: app.AuthKeeper, + BankKeeper: app.BankKeeper, + ConsensusKeeper: app.ConsensusParamsKeeper, + SignModeHandler: app.txConfig.SignModeHandler(), + FeegrantKeeper: app.FeeGrantKeeper, + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + UnorderedTxManager: app.UnorderedTxManager, + Environment: app.AuthKeeper.Environment, + AccountAbstractionKeeper: app.AccountsKeeper, }, &app.CircuitBreakerKeeper, }, diff --git a/x/validate/depinject.go b/x/validate/depinject.go index 0c383f457abe..e0e6e14f3a0e 100644 --- a/x/validate/depinject.go +++ b/x/validate/depinject.go @@ -138,14 +138,15 @@ func newBaseAppOption(in ModuleInputs) func(app *baseapp.BaseApp) { func newAnteHandler(in ModuleInputs) (sdk.AnteHandler, error) { anteHandler, err := ante.NewAnteHandler( ante.HandlerOptions{ - Environment: in.Environment, - AccountKeeper: in.AccountKeeper, - ConsensusKeeper: in.ConsensusKeeper, - BankKeeper: in.BankKeeper, - SignModeHandler: in.TxConfig.SignModeHandler(), - FeegrantKeeper: in.FeeGrantKeeper, - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - UnorderedTxManager: in.UnorderedTxManager, + Environment: in.Environment, + AccountKeeper: in.AccountKeeper, + ConsensusKeeper: in.ConsensusKeeper, + BankKeeper: in.BankKeeper, + SignModeHandler: in.TxConfig.SignModeHandler(), + FeegrantKeeper: in.FeeGrantKeeper, + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + UnorderedTxManager: in.UnorderedTxManager, + AccountAbstractionKeeper: in.AccountAbstractionKeeper, }, ) if err != nil { From a4103602193aa42a00d04e11f8566cd1e72f2602 Mon Sep 17 00:00:00 2001 From: akhilkumarpilli Date: Mon, 11 Nov 2024 18:52:13 +0530 Subject: [PATCH 6/6] fix block test --- tests/integration/baseapp/block_gas_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/baseapp/block_gas_test.go b/tests/integration/baseapp/block_gas_test.go index f883b68db9f4..97086e20db0f 100644 --- a/tests/integration/baseapp/block_gas_test.go +++ b/tests/integration/baseapp/block_gas_test.go @@ -172,7 +172,7 @@ func TestBaseApp_BlockGas(t *testing.T) { require.Equal(t, []byte("ok"), okValue) } // check block gas is always consumed - baseGas := uint64(38142) // baseGas is the gas consumed before tx msg + baseGas := uint64(39205) // baseGas is the gas consumed before tx msg expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas) if expGasConsumed > uint64(simtestutil.DefaultConsensusParams.Block.MaxGas) { // capped by gasLimit