From 31a707357b2fa457d0ef9cda15df1e5ce6eb88be Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 17:27:03 +0900 Subject: [PATCH] fix: rename function name and add a contract for order --- CHANGELOG.md | 1 - x/wasmplus/keeper/querier_test.go | 14 +++++++++----- x/wasmplus/keeper/test_common.go | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 765634c8b9..ba8674924b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,6 @@ * [\#71](https://github.com/Finschia/wasmd/pull/71) add test cases in ContractsByCode * [\#82](https://github.com/Finschia/wasmd/pull/82) add test case to QueryInactiveContracts - ### Bug Fixes * [\#62](https://github.com/Finschia/wasmd/pull/62) fill ContractHistory querier result's Updated field * [\#52](https://github.com/Finschia/wasmd/pull/52) fix cli_test error of wasmplus and add cli_test ci diff --git a/x/wasmplus/keeper/querier_test.go b/x/wasmplus/keeper/querier_test.go index 6982b1ce41..1574c0c7e1 100644 --- a/x/wasmplus/keeper/querier_test.go +++ b/x/wasmplus/keeper/querier_test.go @@ -23,15 +23,19 @@ func TestQueryInactiveContracts(t *testing.T) { ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) example2 := InstantiateHackatomExampleContract(t, ctx, keepers) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + example3 := InstantiateHackatomExampleContract(t, ctx, keepers) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) // Address order of contracts is ascending order of byte array whose address is decoded by bech32 - expAddrs := CreateOrderedAddresses(example1.Contract.Bytes(), example2.Contract.Bytes()) + expAddrs := GenerateSortedBech32Address(example1.Contract.Bytes(), example2.Contract.Bytes(), example3.Contract.Bytes()) // set inactive err := keeper.deactivateContract(ctx, example1.Contract) require.NoError(t, err) err = keeper.deactivateContract(ctx, example2.Contract) require.NoError(t, err) + err = keeper.deactivateContract(ctx, example3.Contract) + require.NoError(t, err) q := Querier(keeper) specs := map[string]struct { @@ -47,7 +51,7 @@ func TestQueryInactiveContracts(t *testing.T) { "query all": { srcQuery: &types.QueryInactiveContractsRequest{}, expAddrs: expAddrs, - expPaginationTotal: 2, + expPaginationTotal: 3, }, "with pagination offset": { srcQuery: &types.QueryInactiveContractsRequest{ @@ -55,8 +59,8 @@ func TestQueryInactiveContracts(t *testing.T) { Offset: 1, }, }, - expAddrs: []string{expAddrs[1]}, - expPaginationTotal: 2, + expAddrs: []string{expAddrs[1], expAddrs[2]}, + expPaginationTotal: 3, }, "with invalid pagination key": { srcQuery: &types.QueryInactiveContractsRequest{ @@ -82,7 +86,7 @@ func TestQueryInactiveContracts(t *testing.T) { Key: fromBase64("reSl9YA6Q5g1xjY5Wo1kje5XsvyQ2Y3Bf6iHFZtpY4s="), }, }, - expAddrs: []string{expAddrs[1]}, + expAddrs: []string{expAddrs[1], expAddrs[2]}, expPaginationTotal: 0, }, } diff --git a/x/wasmplus/keeper/test_common.go b/x/wasmplus/keeper/test_common.go index bee66aa1b1..875db8485c 100644 --- a/x/wasmplus/keeper/test_common.go +++ b/x/wasmplus/keeper/test_common.go @@ -690,7 +690,7 @@ func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { return key, pub, addr } -func CreateOrderedAddresses(addrs ...[]byte) []string { +func GenerateSortedBech32Address(addrs ...[]byte) []string { sort.Slice(addrs, func(i, j int) bool { return string(addrs[i]) < string(addrs[j]) })