Skip to content

Commit 3e48db8

Browse files
committed
refactor tests
1 parent f04ddfe commit 3e48db8

File tree

24 files changed

+11273
-192
lines changed

24 files changed

+11273
-192
lines changed

MIGRATION_GUIDE.md

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,43 +71,7 @@ contractData = ContractData{
7171
}
7272
```
7373

74-
### 3. Create Helper Functions
75-
76-
Add these helper functions to your test_utils.go:
77-
78-
```go
79-
// decodeBalancesResult decodes the result from a balances query
80-
func decodeBalancesResult(data []byte) ([]bank.Balance, error) {
81-
var result bank.BalancesReturn
82-
_, err := result.Decode(data)
83-
if err != nil {
84-
return nil, err
85-
}
86-
return result.Balances, nil
87-
}
88-
89-
// decodeTotalSupplyResult decodes the result from a totalSupply query
90-
func decodeTotalSupplyResult(data []byte) ([]bank.Balance, error) {
91-
var result bank.TotalSupplyReturn
92-
_, err := result.Decode(data)
93-
if err != nil {
94-
return nil, err
95-
}
96-
return result.TotalSupply, nil
97-
}
98-
99-
// decodeSupplyOfResult decodes the result from a supplyOf query
100-
func decodeSupplyOfResult(data []byte) (*big.Int, error) {
101-
var result bank.SupplyOfReturn
102-
_, err := result.Decode(data)
103-
if err != nil {
104-
return nil, err
105-
}
106-
return result.TotalSupply, nil
107-
}
108-
```
109-
110-
### 4. Update getTxAndCallArgs Function
74+
### 3. Update getTxAndCallArgs Function
11175

11276
This function handles encoding for direct precompile calls. Replace manual encoding with `EncodeWithSelector()`:
11377

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ require (
4646
github.com/tidwall/gjson v1.18.0
4747
github.com/tidwall/sjson v1.2.5
4848
github.com/tyler-smith/go-bip39 v1.1.0
49-
github.com/yihuang/go-abi v0.0.0-20251101094340-01f258e337df
49+
github.com/yihuang/go-abi v0.0.0-20251102022042-b0606a905691
5050
github.com/zondax/hid v0.9.2
5151
go.uber.org/mock v0.6.0
5252
golang.org/x/crypto v0.43.0
@@ -265,6 +265,7 @@ require (
265265
go.yaml.in/yaml/v3 v3.0.4 // indirect
266266
golang.org/x/arch v0.21.0 // indirect
267267
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
268+
golang.org/x/mod v0.28.0 // indirect
268269
golang.org/x/oauth2 v0.31.0 // indirect
269270
golang.org/x/sys v0.37.0 // indirect
270271
golang.org/x/term v0.36.0 // indirect

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,12 @@ github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX
955955
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
956956
github.com/yihuang/go-abi v0.0.0-20251101094340-01f258e337df h1:4y8VMbxn7j2LktNlHaFjq01QHJVioJI2ZfXZaYC1BOI=
957957
github.com/yihuang/go-abi v0.0.0-20251101094340-01f258e337df/go.mod h1:btymTlqoiLCR8Gj5bppalyNPSzQYUfK6YROYsihjGS4=
958+
github.com/yihuang/go-abi v0.0.0-20251102014452-d8312fb44b32 h1:r9w2T0iK6At4WF57X/Rl0/Q1JLmSI2GRstEOix9ZUvg=
959+
github.com/yihuang/go-abi v0.0.0-20251102014452-d8312fb44b32/go.mod h1:btymTlqoiLCR8Gj5bppalyNPSzQYUfK6YROYsihjGS4=
960+
github.com/yihuang/go-abi v0.0.0-20251102015743-d0a5d5de5ebd h1:q5G33zAXGgIqZwhtBc77knzLU66F7waUIMLem1C/tTE=
961+
github.com/yihuang/go-abi v0.0.0-20251102015743-d0a5d5de5ebd/go.mod h1:btymTlqoiLCR8Gj5bppalyNPSzQYUfK6YROYsihjGS4=
962+
github.com/yihuang/go-abi v0.0.0-20251102022042-b0606a905691 h1:0sipPjUO70h/Vf0cvYp9Qv5B6bO8EieKMr+7ZGX5E+I=
963+
github.com/yihuang/go-abi v0.0.0-20251102022042-b0606a905691/go.mod h1:btymTlqoiLCR8Gj5bppalyNPSzQYUfK6YROYsihjGS4=
958964
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
959965
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
960966
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
@@ -1062,6 +1068,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
10621068
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
10631069
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
10641070
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
1071+
golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U=
1072+
golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=
10651073
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
10661074
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
10671075
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

precompiles/bank/bank.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const (
3434
GasSupplyOf = 2_477
3535
)
3636

37-
//go:generate go run github.com/yihuang/go-abi/cmd -input abi.json -module bank
37+
//go:generate go run github.com/yihuang/go-abi/cmd -input abi.json -output bank.abi.go
3838

3939
var _ vm.PrecompiledContract = &Precompile{}
4040

precompiles/bech32/bech32.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
evmtypes "github.com/cosmos/evm/x/vm/types"
1111
)
1212

13-
//go:generate go run github.com/yihuang/go-abi/cmd -input abi.json -module bech32
13+
//go:generate go run github.com/yihuang/go-abi/cmd -input abi.json -output bech32.abi.go
1414

1515
var _ vm.PrecompiledContract = &Precompile{}
1616

precompiles/callbacks/abi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package callbacks
22

3-
//go:generate go run github.com/yihuang/go-abi/cmd -input abi.json -module callback -external-tuples Coin=cmn.Coin,Dec=cmn.Dec,DecCoin=cmn.DecCoin,PageRequest=cmn.PageRequest -imports cmn=github.com/cosmos/evm/precompiles/common
3+
//go:generate go run github.com/yihuang/go-abi/cmd -input abi.json -output callback.abi.go -external-tuples Coin=cmn.Coin,Dec=cmn.Dec,DecCoin=cmn.DecCoin,PageRequest=cmn.PageRequest -imports cmn=github.com/cosmos/evm/precompiles/common

precompiles/common/abi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/yihuang/go-abi"
66
)
77

8-
//go:generate go run github.com/yihuang/go-abi/cmd -var=CommonABI -module common
8+
//go:generate go run github.com/yihuang/go-abi/cmd -var=CommonABI -output common.abi.go
99

1010
var CommonABI = []string{
1111
"struct Coin {string denom; uint256 amount;}",

precompiles/distribution/distribution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
2020
)
2121

22-
//go:generate go run github.com/yihuang/go-abi/cmd -input abi.json -module distribution -external-tuples Coin=cmn.Coin,Dec=cmn.Dec,DecCoin=cmn.DecCoin,PageRequest=cmn.PageRequest -imports cmn=github.com/cosmos/evm/precompiles/common
22+
//go:generate go run github.com/yihuang/go-abi/cmd -input abi.json -output distribution.abi.go -external-tuples Coin=cmn.Coin,Dec=cmn.Dec,DecCoin=cmn.DecCoin,PageRequest=cmn.PageRequest -imports cmn=github.com/cosmos/evm/precompiles/common
2323

2424
var _ vm.PrecompiledContract = &Precompile{}
2525

precompiles/erc20/erc20.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
sdk "github.com/cosmos/cosmos-sdk/types"
1818
)
1919

20-
//go:generate go run github.com/yihuang/go-abi/cmd -input abi.json -module erc20
20+
//go:generate go run github.com/yihuang/go-abi/cmd -input abi.json -output erc20.abi.go
2121

2222
const (
2323
// NOTE: These gas values have been derived from tests that have been concluded on a testing branch, which

precompiles/gov/gov.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
2121
)
2222

23-
//go:generate go run github.com/yihuang/go-abi/cmd -input abi.json -module gov -external-tuples Coin=cmn.Coin,Dec=cmn.Dec,DecCoin=cmn.DecCoin,PageRequest=cmn.PageRequest,PageResponse=cmn.PageResponse -imports cmn=github.com/cosmos/evm/precompiles/common
23+
//go:generate go run github.com/yihuang/go-abi/cmd -input abi.json -output gov.abi.go -external-tuples Coin=cmn.Coin,Dec=cmn.Dec,DecCoin=cmn.DecCoin,PageRequest=cmn.PageRequest,PageResponse=cmn.PageResponse -imports cmn=github.com/cosmos/evm/precompiles/common
2424

2525
var _ vm.PrecompiledContract = &Precompile{}
2626

0 commit comments

Comments
 (0)