From 5d9dc401275a329f48157e2aa8fcdb835ec2a07c Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Thu, 17 Aug 2023 23:07:45 +0900 Subject: [PATCH 01/21] test: add test case to `QueryInactiveContracts` --- x/wasmplus/keeper/querier_test.go | 83 ++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/x/wasmplus/keeper/querier_test.go b/x/wasmplus/keeper/querier_test.go index 7d445a0bf3..d7ad78f411 100644 --- a/x/wasmplus/keeper/querier_test.go +++ b/x/wasmplus/keeper/querier_test.go @@ -1,6 +1,9 @@ package keeper import ( + "encoding/base64" + "fmt" + "github.com/Finschia/finschia-sdk/types/query" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" @@ -28,13 +31,81 @@ func TestQueryInactiveContracts(t *testing.T) { require.NoError(t, err) q := Querier(keeper) - rq := types.QueryInactiveContractsRequest{} - res, err := q.InactiveContracts(sdk.WrapSDKContext(ctx), &rq) - require.NoError(t, err) - expect := []string{example1.Contract.String(), example2.Contract.String()} - for _, exp := range expect { - assert.Contains(t, res.Addresses, exp) + specs := map[string]struct { + srcQuery *types.QueryInactiveContractsRequest + expAddrs []string + expPaginationTotal uint64 + expErr error + }{ + "req nil": { + srcQuery: nil, + expErr: status.Error(codes.InvalidArgument, "empty request"), + }, + "query all": { + srcQuery: &types.QueryInactiveContractsRequest{}, + expAddrs: []string{example1.Contract.String(), example2.Contract.String()}, + expPaginationTotal: 2, + }, + "with pagination offset": { + srcQuery: &types.QueryInactiveContractsRequest{ + Pagination: &query.PageRequest{ + Offset: 1, + }, + }, + expAddrs: []string{example1.Contract.String()}, + expPaginationTotal: 2, + }, + "with invalid pagination key": { + srcQuery: &types.QueryInactiveContractsRequest{ + Pagination: &query.PageRequest{ + Offset: 1, + Key: []byte("test"), + }, + }, + expErr: fmt.Errorf("invalid request, either offset or key is expected, got both"), + }, + "with pagination limit": { + srcQuery: &types.QueryInactiveContractsRequest{ + Pagination: &query.PageRequest{ + Limit: 1, + }, + }, + expAddrs: []string{example2.Contract.String()}, + expPaginationTotal: 0, + }, + "with pagination next key": { + srcQuery: &types.QueryInactiveContractsRequest{ + Pagination: &query.PageRequest{ + Key: fromBase64("AAAAAAAAAAM="), + }, + }, + expAddrs: []string{}, + expPaginationTotal: 0, + }, + } + + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + got, err := q.InactiveContracts(sdk.WrapSDKContext(ctx), spec.srcQuery) + if spec.expErr != nil { + require.Equal(t, spec.expErr, err, "but got %+v", err) + return + } + require.NoError(t, err) + for _, expAddr := range spec.expAddrs { + assert.Contains(t, got.Addresses, expAddr) + } + assert.EqualValues(t, spec.expPaginationTotal, got.Pagination.Total) + }) + } +} + +func fromBase64(s string) []byte { + r, err := base64.StdEncoding.DecodeString(s) + if err != nil { + panic(err) } + return r } func TestQueryInactiveContract(t *testing.T) { From 52ba9b8745fdbb7c4be5407abcbe28a14b24f42d Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Thu, 17 Aug 2023 23:14:47 +0900 Subject: [PATCH 02/21] chore: add this pr for changelog.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c30d83814..99e3aa427b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * [\#73](https://github.com/Finschia/wasmd/pull/73) test: add the check for expPaginationTotal * [\#72](https://github.com/Finschia/wasmd/pull/72) add pagination next key test in ContractHistory * [\#75](https://github.com/Finschia/wasmd/pull/75) test: add the test case for InactiveContract +* [\#82](https://github.com/Finschia/wasmd/pull/82) test: add test case to QueryInactiveContracts ### Bug Fixes * [\#62](https://github.com/Finschia/wasmd/pull/62) fill ContractHistory querier result's Updated field From 6e2e797e73793e72c5816ea1046fac509439df2c Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Mon, 21 Aug 2023 01:13:23 +0900 Subject: [PATCH 03/21] test: add the test case for invalid address --- x/wasm/keeper/querier_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index aa75fb4d8c..626fc8b4fa 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + "github.com/cosmos/btcutil/bech32" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" @@ -55,6 +56,10 @@ func TestQueryAllContractState(t *testing.T) { srcQuery: &types.QueryAllContractStateRequest{Address: RandomBech32AccountAddress(t)}, expErr: types.ErrNotFound, }, + "query all with invalid address": { + srcQuery: &types.QueryAllContractStateRequest{Address: "abcde"}, + expErr: bech32.ErrInvalidLength(5), + }, "with pagination offset": { srcQuery: &types.QueryAllContractStateRequest{ Address: contractAddr.String(), @@ -119,6 +124,10 @@ func TestQueryAllContractState(t *testing.T) { t.Run(msg, func(t *testing.T) { got, err := q.AllContractState(sdk.WrapSDKContext(ctx), spec.srcQuery) if spec.expErr != nil { + if errors.Is(err, spec.expErr) { + require.True(t, errors.Is(err, spec.expErr)) + return + } require.Equal(t, spec.expErr, err, "but got %+v", err) return } @@ -163,6 +172,10 @@ func TestQuerySmartContractState(t *testing.T) { srcQuery: &types.QuerySmartContractStateRequest{Address: RandomBech32AccountAddress(t), QueryData: []byte(`{"verifier":{}}`)}, expErr: types.ErrNotFound, }, + "query smart with invalid address": { + srcQuery: &types.QuerySmartContractStateRequest{Address: "abcde", QueryData: []byte(`{"verifier":{}}`)}, + expErr: bech32.ErrInvalidLength(5), + }, "with empty request": { srcQuery: nil, expErr: status.Error(codes.InvalidArgument, "empty request"), From 8b6ceb9d13d1e81a7b6bcbfa71025c4f4a78e74e Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Mon, 21 Aug 2023 01:13:23 +0900 Subject: [PATCH 04/21] test: add the test case for invalid address --- x/wasm/keeper/querier_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index aa75fb4d8c..8113b8cbd2 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + "github.com/cosmos/btcutil/bech32" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" @@ -55,6 +56,10 @@ func TestQueryAllContractState(t *testing.T) { srcQuery: &types.QueryAllContractStateRequest{Address: RandomBech32AccountAddress(t)}, expErr: types.ErrNotFound, }, + "query all with invalid address": { + srcQuery: &types.QueryAllContractStateRequest{Address: "abcde"}, + expErr: bech32.ErrInvalidLength(5), + }, "with pagination offset": { srcQuery: &types.QueryAllContractStateRequest{ Address: contractAddr.String(), @@ -119,6 +124,10 @@ func TestQueryAllContractState(t *testing.T) { t.Run(msg, func(t *testing.T) { got, err := q.AllContractState(sdk.WrapSDKContext(ctx), spec.srcQuery) if spec.expErr != nil { + if errors.Unwrap(err) != nil { + require.True(t, errors.Is(err, spec.expErr)) + return + } require.Equal(t, spec.expErr, err, "but got %+v", err) return } @@ -163,6 +172,10 @@ func TestQuerySmartContractState(t *testing.T) { srcQuery: &types.QuerySmartContractStateRequest{Address: RandomBech32AccountAddress(t), QueryData: []byte(`{"verifier":{}}`)}, expErr: types.ErrNotFound, }, + "query smart with invalid address": { + srcQuery: &types.QuerySmartContractStateRequest{Address: "abcde", QueryData: []byte(`{"verifier":{}}`)}, + expErr: bech32.ErrInvalidLength(5), + }, "with empty request": { srcQuery: nil, expErr: status.Error(codes.InvalidArgument, "empty request"), @@ -267,6 +280,10 @@ func TestQueryRawContractState(t *testing.T) { srcQuery: &types.QueryRawContractStateRequest{Address: RandomBech32AccountAddress(t), QueryData: []byte("foo")}, expErr: types.ErrNotFound, }, + "query raw with invalid address": { + srcQuery: &types.QueryRawContractStateRequest{Address: "abcde", QueryData: []byte("foo")}, + expErr: bech32.ErrInvalidLength(5), + }, "with empty request": { srcQuery: nil, expErr: status.Error(codes.InvalidArgument, "empty request"), From 2aa2c606a45b463b56319e2e378c5d1745855a23 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Mon, 21 Aug 2023 10:19:41 +0900 Subject: [PATCH 05/21] chore: add this pr to CHANGE.log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c30d83814..a0e4b3423a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * [\#73](https://github.com/Finschia/wasmd/pull/73) test: add the check for expPaginationTotal * [\#72](https://github.com/Finschia/wasmd/pull/72) add pagination next key test in ContractHistory * [\#75](https://github.com/Finschia/wasmd/pull/75) test: add the test case for InactiveContract +* [\#88](https://github.com/Finschia/wasmd/pull/88) add the test case for invalid address ### Bug Fixes * [\#62](https://github.com/Finschia/wasmd/pull/62) fill ContractHistory querier result's Updated field From 7e3daa926e0c0c1ed5cc9a87a45e92b0e6682e75 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Mon, 21 Aug 2023 16:48:22 +0900 Subject: [PATCH 06/21] fix: Fix address judgment and pagination key --- x/wasmplus/keeper/querier_test.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/x/wasmplus/keeper/querier_test.go b/x/wasmplus/keeper/querier_test.go index d7ad78f411..9fac5d1158 100644 --- a/x/wasmplus/keeper/querier_test.go +++ b/x/wasmplus/keeper/querier_test.go @@ -43,7 +43,7 @@ func TestQueryInactiveContracts(t *testing.T) { }, "query all": { srcQuery: &types.QueryInactiveContractsRequest{}, - expAddrs: []string{example1.Contract.String(), example2.Contract.String()}, + expAddrs: []string{example2.Contract.String(), example1.Contract.String()}, expPaginationTotal: 2, }, "with pagination offset": { @@ -76,10 +76,10 @@ func TestQueryInactiveContracts(t *testing.T) { "with pagination next key": { srcQuery: &types.QueryInactiveContractsRequest{ Pagination: &query.PageRequest{ - Key: fromBase64("AAAAAAAAAAM="), + Key: fromBase64("reSl9YA6Q5g1xjY5Wo1kje5XsvyQ2Y3Bf6iHFZtpY4s="), }, }, - expAddrs: []string{}, + expAddrs: []string{example1.Contract.String()}, expPaginationTotal: 0, }, } @@ -92,22 +92,12 @@ func TestQueryInactiveContracts(t *testing.T) { return } require.NoError(t, err) - for _, expAddr := range spec.expAddrs { - assert.Contains(t, got.Addresses, expAddr) - } + assert.Equal(t, spec.expAddrs, got.Addresses) assert.EqualValues(t, spec.expPaginationTotal, got.Pagination.Total) }) } } -func fromBase64(s string) []byte { - r, err := base64.StdEncoding.DecodeString(s) - if err != nil { - panic(err) - } - return r -} - func TestQueryInactiveContract(t *testing.T) { ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper @@ -159,3 +149,11 @@ func TestQueryInactiveContract(t *testing.T) { }) } } + +func fromBase64(s string) []byte { + r, err := base64.StdEncoding.DecodeString(s) + if err != nil { + panic(err) + } + return r +} From 31f724b2ffd89276d41c1e5fb483ae1f4e41fd1c Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 11:03:26 +0900 Subject: [PATCH 07/21] feat: add the function for byte array to use addresses order check --- x/wasmplus/keeper/test_common.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/x/wasmplus/keeper/test_common.go b/x/wasmplus/keeper/test_common.go index 5e9a5d44a2..83b1ce56a6 100644 --- a/x/wasmplus/keeper/test_common.go +++ b/x/wasmplus/keeper/test_common.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "os" + "sort" "testing" "time" @@ -688,3 +689,34 @@ func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { addr := sdk.AccAddress(pub.Address()) return key, pub, addr } + +// implement `Interface` in sort package. +type sortByteArrays [][]byte + +func (b sortByteArrays) Len() int { + return len(b) +} + +func (b sortByteArrays) Less(i, j int) bool { + // bytes package already implements Comparable for []byte. + switch bytes.Compare(b[i], b[j]) { + case -1: + return true + case 0, 1: + return false + default: + panic("not fail-able with `bytes.Comparable` bounded [-1, 1].") + return false + } +} + +func (b sortByteArrays) Swap(i, j int) { + b[j], b[i] = b[i], b[j] +} + +// Public +func SortByteArrays(src [][]byte) [][]byte { + sorted := sortByteArrays(src) + sort.Sort(sorted) + return sorted +} From a6d35776b3e1fa8ecb21731638124fa9946941dc Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 11:45:02 +0900 Subject: [PATCH 08/21] test: add func for make test data for addresses order --- x/wasmplus/keeper/test_common.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/x/wasmplus/keeper/test_common.go b/x/wasmplus/keeper/test_common.go index 83b1ce56a6..cd35ef59ca 100644 --- a/x/wasmplus/keeper/test_common.go +++ b/x/wasmplus/keeper/test_common.go @@ -10,6 +10,8 @@ import ( "testing" "time" + "github.com/btcsuite/btcutil/bech32" + "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -720,3 +722,17 @@ func SortByteArrays(src [][]byte) [][]byte { sort.Sort(sorted) return sorted } + +// Decode decodes a Bech32-encoded string to a 8-bits per byte byte-slice. +func Decode(text string) (string, []byte, error) { + // NOTE: Taken from github.com/tendermint/tendermint/libs/bech32 (licensed under Apache-2). + hrp, data, err := bech32.Decode(text) + if err != nil { + return "", nil, fmt.Errorf("decoding bech32 failed: %w", err) + } + converted, err := bech32.ConvertBits(data, 5, 8, false) + if err != nil { + return "", nil, fmt.Errorf("decoding bech32 failed: %w", err) + } + return hrp, converted, nil +} From fac0982401c48b06910db295831366129cebe4d6 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 14:23:06 +0900 Subject: [PATCH 09/21] fix: Add a function to create an ordered address array Fix to create an ordered address array and test it as an expected value --- go.mod | 1 + go.sum | 16 ++++++++++++++++ x/wasmplus/keeper/querier_test.go | 11 +++++++---- x/wasmplus/keeper/test_common.go | 26 ++++++++++++++++++++++++-- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index de862264c7..b9eada5796 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/Finschia/finschia-sdk v0.48.0-rc1 github.com/Finschia/ostracon v1.1.1 github.com/Finschia/wasmvm v1.1.1-0.11.2.0.20230418093236-ce70a3856778 + github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/cosmos/iavl v0.19.4 github.com/cosmos/ibc-go/v4 v4.3.1 github.com/dvsekhvalnov/jose2go v1.5.0 diff --git a/go.sum b/go.sum index bea2f3569c..6a9783ae61 100644 --- a/go.sum +++ b/go.sum @@ -71,6 +71,7 @@ github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/ github.com/Workiva/go-datastructures v1.1.0 h1:hu20UpgZneBhQ3ZvwiOGlqJSKIosin2Rd5wAKUHEO/k= github.com/Workiva/go-datastructures v1.1.0/go.mod h1:1yZL+zfsztete+ePzZz/Zb1/t5BnDuE2Ya2MMGhzP6A= github.com/adlio/schema v1.3.4 h1:8K+41sfQkxfT6a79aLBxx+dBKcid6Raw2JPk5COqeqE= +github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -99,11 +100,20 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c= github.com/btcsuite/btcd v0.22.1/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y= github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= +github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ= +github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= +github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= +github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= +github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= @@ -155,6 +165,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= +github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -384,6 +395,7 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= +github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jhump/protoreflect v1.12.1-0.20220721211354-060cc04fc18b h1:izTof8BKh/nE1wrKOrloNA5q4odOarjf+Xpe+4qow98= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U= @@ -392,6 +404,7 @@ github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22 github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= +github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -405,6 +418,7 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= @@ -711,6 +725,7 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9E go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= +golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -720,6 +735,7 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= diff --git a/x/wasmplus/keeper/querier_test.go b/x/wasmplus/keeper/querier_test.go index 9fac5d1158..21c3c2a082 100644 --- a/x/wasmplus/keeper/querier_test.go +++ b/x/wasmplus/keeper/querier_test.go @@ -24,6 +24,9 @@ func TestQueryInactiveContracts(t *testing.T) { example2 := 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, example2.Contract) + // set inactive err := keeper.deactivateContract(ctx, example1.Contract) require.NoError(t, err) @@ -43,7 +46,7 @@ func TestQueryInactiveContracts(t *testing.T) { }, "query all": { srcQuery: &types.QueryInactiveContractsRequest{}, - expAddrs: []string{example2.Contract.String(), example1.Contract.String()}, + expAddrs: expAddrs, expPaginationTotal: 2, }, "with pagination offset": { @@ -52,7 +55,7 @@ func TestQueryInactiveContracts(t *testing.T) { Offset: 1, }, }, - expAddrs: []string{example1.Contract.String()}, + expAddrs: []string{expAddrs[1]}, expPaginationTotal: 2, }, "with invalid pagination key": { @@ -70,7 +73,7 @@ func TestQueryInactiveContracts(t *testing.T) { Limit: 1, }, }, - expAddrs: []string{example2.Contract.String()}, + expAddrs: []string{expAddrs[0]}, expPaginationTotal: 0, }, "with pagination next key": { @@ -79,7 +82,7 @@ func TestQueryInactiveContracts(t *testing.T) { Key: fromBase64("reSl9YA6Q5g1xjY5Wo1kje5XsvyQ2Y3Bf6iHFZtpY4s="), }, }, - expAddrs: []string{example1.Contract.String()}, + expAddrs: []string{expAddrs[1]}, expPaginationTotal: 0, }, } diff --git a/x/wasmplus/keeper/test_common.go b/x/wasmplus/keeper/test_common.go index cd35ef59ca..510e9bc2a5 100644 --- a/x/wasmplus/keeper/test_common.go +++ b/x/wasmplus/keeper/test_common.go @@ -716,16 +716,23 @@ func (b sortByteArrays) Swap(i, j int) { b[j], b[i] = b[i], b[j] } -// Public func SortByteArrays(src [][]byte) [][]byte { sorted := sortByteArrays(src) sort.Sort(sorted) return sorted } +// Encode encodes 8-bits per byte byte-slice to a Bech32-encoded string. +func Encode(hrp string, data []byte) (string, error) { + converted, err := bech32.ConvertBits(data, 8, 5, true) + if err != nil { + return "", fmt.Errorf("encoding bech32 failed: %w", err) + } + return bech32.Encode(hrp, converted) +} + // Decode decodes a Bech32-encoded string to a 8-bits per byte byte-slice. func Decode(text string) (string, []byte, error) { - // NOTE: Taken from github.com/tendermint/tendermint/libs/bech32 (licensed under Apache-2). hrp, data, err := bech32.Decode(text) if err != nil { return "", nil, fmt.Errorf("decoding bech32 failed: %w", err) @@ -736,3 +743,18 @@ func Decode(text string) (string, []byte, error) { } return hrp, converted, nil } + +func CreateOrderedAddresses(addrs ...sdk.AccAddress) []string { + // Address order of contracts is ascending order of byte array whose address is decoded by bech32 + byteAddrs := make([][]byte, len(addrs)) + for i, addr := range addrs { + _, byteAddrs[i], _ = Decode(addr.String()) + } + sortedByteAddrs := SortByteArrays(byteAddrs) + expAddrs := make([]string, len(sortedByteAddrs)) + for i, v := range sortedByteAddrs { + expAddrs[i], _ = Encode("link", v) + fmt.Println(expAddrs[i]) + } + return expAddrs +} From ec5f793d3f1f75f736e5b1192c45dca42edc6a52 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 14:52:19 +0900 Subject: [PATCH 10/21] fix: fix lint error --- x/wasmplus/keeper/test_common.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/x/wasmplus/keeper/test_common.go b/x/wasmplus/keeper/test_common.go index 510e9bc2a5..8f990f7b7d 100644 --- a/x/wasmplus/keeper/test_common.go +++ b/x/wasmplus/keeper/test_common.go @@ -747,14 +747,23 @@ func Decode(text string) (string, []byte, error) { func CreateOrderedAddresses(addrs ...sdk.AccAddress) []string { // Address order of contracts is ascending order of byte array whose address is decoded by bech32 byteAddrs := make([][]byte, len(addrs)) + for i, addr := range addrs { - _, byteAddrs[i], _ = Decode(addr.String()) + var err error + _, byteAddrs[i], err = Decode(addr.String()) + if err != nil { + panic("decoding bech32 failed, so make sure the address is bech32 encode") + } } + sortedByteAddrs := SortByteArrays(byteAddrs) expAddrs := make([]string, len(sortedByteAddrs)) for i, v := range sortedByteAddrs { - expAddrs[i], _ = Encode("link", v) - fmt.Println(expAddrs[i]) + var err error + expAddrs[i], err = Encode("link", v) + if err != nil { + panic("encoding bech32 failed") + } } return expAddrs } From 64d554f563b9cb06b6531f1cd2bd87852208548d Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 15:10:00 +0900 Subject: [PATCH 11/21] fix: add the error handling for lint --- x/wasmplus/keeper/querier_test.go | 5 +++-- x/wasmplus/keeper/test_common.go | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/x/wasmplus/keeper/querier_test.go b/x/wasmplus/keeper/querier_test.go index 21c3c2a082..fa3d0fa475 100644 --- a/x/wasmplus/keeper/querier_test.go +++ b/x/wasmplus/keeper/querier_test.go @@ -25,10 +25,11 @@ func TestQueryInactiveContracts(t *testing.T) { 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, example2.Contract) + expAddrs, err := CreateOrderedAddresses(example1.Contract, example2.Contract) + require.NoError(t, err) // set inactive - err := keeper.deactivateContract(ctx, example1.Contract) + err = keeper.deactivateContract(ctx, example1.Contract) require.NoError(t, err) err = keeper.deactivateContract(ctx, example2.Contract) require.NoError(t, err) diff --git a/x/wasmplus/keeper/test_common.go b/x/wasmplus/keeper/test_common.go index 8f990f7b7d..3f7d1511bc 100644 --- a/x/wasmplus/keeper/test_common.go +++ b/x/wasmplus/keeper/test_common.go @@ -744,7 +744,7 @@ func Decode(text string) (string, []byte, error) { return hrp, converted, nil } -func CreateOrderedAddresses(addrs ...sdk.AccAddress) []string { +func CreateOrderedAddresses(addrs ...sdk.AccAddress) ([]string, error) { // Address order of contracts is ascending order of byte array whose address is decoded by bech32 byteAddrs := make([][]byte, len(addrs)) @@ -752,7 +752,7 @@ func CreateOrderedAddresses(addrs ...sdk.AccAddress) []string { var err error _, byteAddrs[i], err = Decode(addr.String()) if err != nil { - panic("decoding bech32 failed, so make sure the address is bech32 encode") + return nil, fmt.Errorf("decoding bech32 failed, so make sure the address is bech32 encode %w", err) } } @@ -762,8 +762,8 @@ func CreateOrderedAddresses(addrs ...sdk.AccAddress) []string { var err error expAddrs[i], err = Encode("link", v) if err != nil { - panic("encoding bech32 failed") + return nil, fmt.Errorf("encoding to link address failed %w", err) } } - return expAddrs + return expAddrs, nil } From 69f73deef706a943c37efce08182bb7733c36dfb Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 15:22:06 +0900 Subject: [PATCH 12/21] fix: fix `Error: unreachable: unreachable code (govet)` for `golangci-lint` --- x/wasmplus/keeper/test_common.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/wasmplus/keeper/test_common.go b/x/wasmplus/keeper/test_common.go index 3f7d1511bc..e24adafa6f 100644 --- a/x/wasmplus/keeper/test_common.go +++ b/x/wasmplus/keeper/test_common.go @@ -708,7 +708,6 @@ func (b sortByteArrays) Less(i, j int) bool { return false default: panic("not fail-able with `bytes.Comparable` bounded [-1, 1].") - return false } } From 159ef4bf589a874a44dd7ce02d84b800f669437a Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 15:26:27 +0900 Subject: [PATCH 13/21] fix: fix panic message --- x/wasmplus/keeper/test_common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/wasmplus/keeper/test_common.go b/x/wasmplus/keeper/test_common.go index e24adafa6f..4b30d5a8ef 100644 --- a/x/wasmplus/keeper/test_common.go +++ b/x/wasmplus/keeper/test_common.go @@ -707,7 +707,7 @@ func (b sortByteArrays) Less(i, j int) bool { case 0, 1: return false default: - panic("not fail-able with `bytes.Comparable` bounded [-1, 1].") + panic("Not defined.") } } From 27a7bd775175760245cc619519ddb95ee3edb56a Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 15:56:03 +0900 Subject: [PATCH 14/21] refactor: Changed []byte array comparison to string comparison --- x/wasmplus/keeper/querier_test.go | 5 +- x/wasmplus/keeper/test_common.go | 80 +++++-------------------------- 2 files changed, 14 insertions(+), 71 deletions(-) diff --git a/x/wasmplus/keeper/querier_test.go b/x/wasmplus/keeper/querier_test.go index fa3d0fa475..6982b1ce41 100644 --- a/x/wasmplus/keeper/querier_test.go +++ b/x/wasmplus/keeper/querier_test.go @@ -25,11 +25,10 @@ func TestQueryInactiveContracts(t *testing.T) { ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) // Address order of contracts is ascending order of byte array whose address is decoded by bech32 - expAddrs, err := CreateOrderedAddresses(example1.Contract, example2.Contract) - require.NoError(t, err) + expAddrs := CreateOrderedAddresses(example1.Contract.Bytes(), example2.Contract.Bytes()) // set inactive - err = keeper.deactivateContract(ctx, example1.Contract) + err := keeper.deactivateContract(ctx, example1.Contract) require.NoError(t, err) err = keeper.deactivateContract(ctx, example2.Contract) require.NoError(t, err) diff --git a/x/wasmplus/keeper/test_common.go b/x/wasmplus/keeper/test_common.go index 4b30d5a8ef..936e7e4bb4 100644 --- a/x/wasmplus/keeper/test_common.go +++ b/x/wasmplus/keeper/test_common.go @@ -10,8 +10,6 @@ import ( "testing" "time" - "github.com/btcsuite/btcutil/bech32" - "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -692,77 +690,23 @@ func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { return key, pub, addr } -// implement `Interface` in sort package. -type sortByteArrays [][]byte - -func (b sortByteArrays) Len() int { - return len(b) -} - -func (b sortByteArrays) Less(i, j int) bool { - // bytes package already implements Comparable for []byte. - switch bytes.Compare(b[i], b[j]) { - case -1: - return true - case 0, 1: - return false - default: - panic("Not defined.") - } -} - -func (b sortByteArrays) Swap(i, j int) { - b[j], b[i] = b[i], b[j] -} - -func SortByteArrays(src [][]byte) [][]byte { - sorted := sortByteArrays(src) - sort.Sort(sorted) - return sorted -} - -// Encode encodes 8-bits per byte byte-slice to a Bech32-encoded string. -func Encode(hrp string, data []byte) (string, error) { - converted, err := bech32.ConvertBits(data, 8, 5, true) - if err != nil { - return "", fmt.Errorf("encoding bech32 failed: %w", err) - } - return bech32.Encode(hrp, converted) -} - -// Decode decodes a Bech32-encoded string to a 8-bits per byte byte-slice. -func Decode(text string) (string, []byte, error) { - hrp, data, err := bech32.Decode(text) - if err != nil { - return "", nil, fmt.Errorf("decoding bech32 failed: %w", err) - } - converted, err := bech32.ConvertBits(data, 5, 8, false) - if err != nil { - return "", nil, fmt.Errorf("decoding bech32 failed: %w", err) - } - return hrp, converted, nil -} - -func CreateOrderedAddresses(addrs ...sdk.AccAddress) ([]string, error) { +func CreateOrderedAddresses(addrs ...[]byte) []string { // Address order of contracts is ascending order of byte array whose address is decoded by bech32 byteAddrs := make([][]byte, len(addrs)) for i, addr := range addrs { - var err error - _, byteAddrs[i], err = Decode(addr.String()) - if err != nil { - return nil, fmt.Errorf("decoding bech32 failed, so make sure the address is bech32 encode %w", err) - } + byteAddrs[i] = addr } - sortedByteAddrs := SortByteArrays(byteAddrs) - expAddrs := make([]string, len(sortedByteAddrs)) - for i, v := range sortedByteAddrs { - var err error - expAddrs[i], err = Encode("link", v) - if err != nil { - return nil, fmt.Errorf("encoding to link address failed %w", err) - } + sort.Slice(byteAddrs, func(i, j int) bool { + return string(byteAddrs[i]) < string(byteAddrs[j]) + }) + + //var sortedAddress []string + expAddrs := make([]string, len(addrs)) + for i, b := range byteAddrs { + expAddrs[i] = sdk.AccAddress(b).String() } - return expAddrs, nil + + return expAddrs } From d119436304876b6df659c3a87c5455d3d001aa34 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 15:58:45 +0900 Subject: [PATCH 15/21] fix: revert commit for go.mod go.sum --- go.mod | 1 - go.sum | 16 ---------------- 2 files changed, 17 deletions(-) diff --git a/go.mod b/go.mod index b9eada5796..de862264c7 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/Finschia/finschia-sdk v0.48.0-rc1 github.com/Finschia/ostracon v1.1.1 github.com/Finschia/wasmvm v1.1.1-0.11.2.0.20230418093236-ce70a3856778 - github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/cosmos/iavl v0.19.4 github.com/cosmos/ibc-go/v4 v4.3.1 github.com/dvsekhvalnov/jose2go v1.5.0 diff --git a/go.sum b/go.sum index 6a9783ae61..bea2f3569c 100644 --- a/go.sum +++ b/go.sum @@ -71,7 +71,6 @@ github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/ github.com/Workiva/go-datastructures v1.1.0 h1:hu20UpgZneBhQ3ZvwiOGlqJSKIosin2Rd5wAKUHEO/k= github.com/Workiva/go-datastructures v1.1.0/go.mod h1:1yZL+zfsztete+ePzZz/Zb1/t5BnDuE2Ya2MMGhzP6A= github.com/adlio/schema v1.3.4 h1:8K+41sfQkxfT6a79aLBxx+dBKcid6Raw2JPk5COqeqE= -github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -100,20 +99,11 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c= github.com/btcsuite/btcd v0.22.1/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y= github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= -github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= -github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ= -github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o= -github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= -github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= -github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= -github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= -github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= @@ -165,7 +155,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= -github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -395,7 +384,6 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= -github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jhump/protoreflect v1.12.1-0.20220721211354-060cc04fc18b h1:izTof8BKh/nE1wrKOrloNA5q4odOarjf+Xpe+4qow98= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U= @@ -404,7 +392,6 @@ github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22 github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= -github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -418,7 +405,6 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= @@ -725,7 +711,6 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9E go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= -golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -735,7 +720,6 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= From 5fd58abc05c2a1306a32198ac18093aa35fd6677 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 16:05:11 +0900 Subject: [PATCH 16/21] fix: fix lint --- x/wasmplus/keeper/test_common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/wasmplus/keeper/test_common.go b/x/wasmplus/keeper/test_common.go index 936e7e4bb4..1c5663c9c2 100644 --- a/x/wasmplus/keeper/test_common.go +++ b/x/wasmplus/keeper/test_common.go @@ -702,7 +702,7 @@ func CreateOrderedAddresses(addrs ...[]byte) []string { return string(byteAddrs[i]) < string(byteAddrs[j]) }) - //var sortedAddress []string + // copy sorted addresses to []string expAddrs := make([]string, len(addrs)) for i, b := range byteAddrs { expAddrs[i] = sdk.AccAddress(b).String() From 760fc355a1c7592402a83360edbacfa0b22a11f0 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 16:09:13 +0900 Subject: [PATCH 17/21] fix: fix lint --- x/wasmplus/keeper/test_common.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/wasmplus/keeper/test_common.go b/x/wasmplus/keeper/test_common.go index 1c5663c9c2..01b31090d4 100644 --- a/x/wasmplus/keeper/test_common.go +++ b/x/wasmplus/keeper/test_common.go @@ -702,7 +702,6 @@ func CreateOrderedAddresses(addrs ...[]byte) []string { return string(byteAddrs[i]) < string(byteAddrs[j]) }) - // copy sorted addresses to []string expAddrs := make([]string, len(addrs)) for i, b := range byteAddrs { expAddrs[i] = sdk.AccAddress(b).String() From d4ca2eadc62f0891f477f9bc425093109cfa23cf Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 16:13:52 +0900 Subject: [PATCH 18/21] fix: delete unnecessary code --- x/wasmplus/keeper/test_common.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/x/wasmplus/keeper/test_common.go b/x/wasmplus/keeper/test_common.go index 01b31090d4..bee66aa1b1 100644 --- a/x/wasmplus/keeper/test_common.go +++ b/x/wasmplus/keeper/test_common.go @@ -691,19 +691,12 @@ func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { } func CreateOrderedAddresses(addrs ...[]byte) []string { - // Address order of contracts is ascending order of byte array whose address is decoded by bech32 - byteAddrs := make([][]byte, len(addrs)) - - for i, addr := range addrs { - byteAddrs[i] = addr - } - - sort.Slice(byteAddrs, func(i, j int) bool { - return string(byteAddrs[i]) < string(byteAddrs[j]) + sort.Slice(addrs, func(i, j int) bool { + return string(addrs[i]) < string(addrs[j]) }) expAddrs := make([]string, len(addrs)) - for i, b := range byteAddrs { + for i, b := range addrs { expAddrs[i] = sdk.AccAddress(b).String() } From 31a707357b2fa457d0ef9cda15df1e5ce6eb88be Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 17:27:03 +0900 Subject: [PATCH 19/21] 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]) }) From ccd91400227aa0c4ed0a0769e0efc523868d8cd1 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Tue, 22 Aug 2023 20:41:35 +0900 Subject: [PATCH 20/21] fix: Changed to equal judgment as before with wrap error as expected value --- x/wasm/keeper/querier_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index 626fc8b4fa..66fd84549c 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -58,7 +58,7 @@ func TestQueryAllContractState(t *testing.T) { }, "query all with invalid address": { srcQuery: &types.QueryAllContractStateRequest{Address: "abcde"}, - expErr: bech32.ErrInvalidLength(5), + expErr: fmt.Errorf("decoding bech32 failed: %w", bech32.ErrInvalidLength(5)), }, "with pagination offset": { srcQuery: &types.QueryAllContractStateRequest{ @@ -124,10 +124,6 @@ func TestQueryAllContractState(t *testing.T) { t.Run(msg, func(t *testing.T) { got, err := q.AllContractState(sdk.WrapSDKContext(ctx), spec.srcQuery) if spec.expErr != nil { - if errors.Is(err, spec.expErr) { - require.True(t, errors.Is(err, spec.expErr)) - return - } require.Equal(t, spec.expErr, err, "but got %+v", err) return } From 0b3c700ac035442eb59b74a4f5d304f478334d44 Mon Sep 17 00:00:00 2001 From: kokeshiM0chi Date: Wed, 23 Aug 2023 11:46:06 +0900 Subject: [PATCH 21/21] test: add the invalid address test case to `TestQueryContractInfo` and `TestQueryContractHistory` --- x/wasm/keeper/querier_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index 630f1bc973..0571f71ffc 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -646,6 +646,16 @@ func TestQueryContractHistory(t *testing.T) { }}, expErr: types.ErrEmpty, }, + "query with invalid address": { + req: &types.QueryContractHistoryRequest{Address: "abcde"}, + srcHistory: []types.ContractCodeHistoryEntry{{ + Operation: types.ContractCodeHistoryOperationTypeGenesis, + CodeID: firstCodeID, + Updated: types.NewAbsoluteTxPosition(ctx), + Msg: []byte(`"init message"`), + }}, + expErr: fmt.Errorf("decoding bech32 failed: %w", bech32.ErrInvalidLength(5)), + }, "with empty request": { req: nil, expErr: status.Error(codes.InvalidArgument, "empty request"), @@ -885,6 +895,10 @@ func TestQueryContractInfo(t *testing.T) { stored: types.ContractInfoFixture(), expErr: types.ErrNotFound, }, + "query with invalid address": { + src: &types.QueryContractInfoRequest{Address: "abcde"}, + expErr: bech32.ErrInvalidLength(5), + }, "with empty request": { src: nil, expErr: status.Error(codes.InvalidArgument, "empty request"),