Skip to content

Commit 17c90ed

Browse files
yihuangclaudehappy-otter
committed
docs: update MIGRATION_GUIDE.md with status and troubleshooting
- Added migration status table for all 10 precompiles - Updated decode examples to show recommended approach (direct Decode) - Added troubleshooting section with common issues and solutions: * s.precompile.Methods undefined * s.precompile.ABI undefined * Too many arguments in calls * Factory calls with CallArgs - Added references to Bech32 and Slashing migrations - Updated examples to be more comprehensive Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]>
1 parent 6e5570d commit 17c90ed

File tree

1 file changed

+101
-2
lines changed

1 file changed

+101
-2
lines changed

MIGRATION_GUIDE.md

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ This guide explains how to migrate precompile integration tests from the old go-
88

99
The precompiles have been refactored to use a custom `go-abi` library instead of the standard `go-ethereum/accounts/abi` package. This change requires updates to the test code to work with the new API.
1010

11+
## Migration Status
12+
13+
| Precompile | Status | Notes |
14+
|------------|--------|-------|
15+
| **Bank** | ✅ Complete | Fully migrated, all tests working |
16+
| **Bech32** | ✅ Complete | Fully migrated, all tests working |
17+
| **Slashing** | 🟡 Partial | Query tests migrated, integration/tx tests need work |
18+
| **P256** | ✅ Complete | Already working, no changes needed |
19+
| **Distribution** | ❌ Pending | Complex test suite, needs migration |
20+
| **ERC20** | ❌ Pending | Many test files, needs migration |
21+
| **Gov** | ❌ Pending | Test files exist, needs migration |
22+
| **ICS20** | ❌ Pending | Complex IBC tests, needs migration |
23+
| **Staking** | ❌ Pending | Large test suite, needs migration |
24+
| **WERC20** | ❌ Pending | Event handling issues, needs migration |
25+
1126
## Key Differences
1227

1328
### Old API (go-ethereum/accounts/abi)
@@ -126,7 +141,15 @@ err = is.precompile.UnpackIntoInterface(&balances, bank2.BalancesMethod, ethRes.
126141
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
127142
```
128143

129-
**After:**
144+
**After (Recommended):**
145+
```go
146+
var ret bank.BalancesReturn
147+
_, err = ret.Decode(ethRes.Ret)
148+
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
149+
Expect(ret.Balances).To(Equal(expectedBalances))
150+
```
151+
152+
**After (With Helper):**
130153
```go
131154
balances, err := decodeBalancesResult(ethRes.Ret)
132155
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
@@ -141,7 +164,15 @@ Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
141164
Expect(out[0].(*big.Int).String()).To(Equal(expectedValue.String()))
142165
```
143166

144-
**After:**
167+
**After (Recommended):**
168+
```go
169+
var ret bank.SupplyOfReturn
170+
_, err = ret.Decode(ethRes.Ret)
171+
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
172+
Expect(ret.TotalSupply.String()).To(Equal(expectedValue.String()))
173+
```
174+
175+
**After (With Helper):**
145176
```go
146177
supply, err := decodeSupplyOfResult(ethRes.Ret)
147178
Expect(err).ToNot(HaveOccurred(), "failed to unpack balances")
@@ -204,8 +235,76 @@ After migration, verify the tests build successfully:
204235
go build -tags=tests ./tests/integration/precompiles/{precompile_name}/...
205236
```
206237

238+
## Common Issues and Solutions
239+
240+
### Issue 1: `s.precompile.Methods` undefined
241+
**Error:** `s.precompile.Methods undefined (type *"github.com/cosmos/evm/precompiles/xxx".Precompile has no field or method Methods)`
242+
243+
**Solution:** The `Methods` field no longer exists. Use typed call structs directly:
244+
```go
245+
// Old:
246+
method := s.precompile.Methods[xxx.SomeMethod]
247+
result, err := s.precompile.SomeMethod(ctx, &method, args)
248+
249+
// New:
250+
var call xxx.SomeCall
251+
result, err := s.precompile.SomeMethod(ctx, &call)
252+
```
253+
254+
### Issue 2: `s.precompile.ABI` undefined
255+
**Error:** `s.precompile.ABI undefined (type *"github.com/cosmos/evm/precompiles/xxx".Precompile has no field or method ABI)`
256+
257+
**Solution:** The `ABI` field no longer exists. For direct precompile calls, encode with `EncodeWithSelector()`:
258+
```go
259+
// Old:
260+
input, err := s.precompile.Pack(xxx.SomeMethod, args...)
261+
s.precompile.UnpackIntoInterface(&out, xxx.SomeMethod, data)
262+
263+
// New:
264+
var call xxx.SomeCall{CreateArgs: args}
265+
input, _ := call.EncodeWithSelector()
266+
var ret xxx.SomeReturn
267+
_, err := ret.Decode(data)
268+
```
269+
270+
### Issue 3: Too many arguments in call
271+
**Error:** `too many arguments in call to s.precompile.SomeMethod`
272+
273+
**Solution:** The new API uses typed structs instead of variadic `[]interface{}`:
274+
```go
275+
// Old:
276+
result, err := s.precompile.SomeMethod(ctx, contract, stateDB, []interface{}{arg1, arg2})
277+
278+
// New:
279+
var call xxx.SomeCall{Arg1: value1, Arg2: value2}
280+
result, err := s.precompile.SomeMethod(ctx, call, stateDB, contract)
281+
```
282+
283+
### Issue 4: Factory calls with CallArgs
284+
**Error:** `cannot use callArgs as "github.com/yihuang/go-abi".Method value`
285+
286+
**Solution:** When calling through factory functions, set the `Method` field in `CallArgs`:
287+
```go
288+
// Old:
289+
callArgs := testutiltypes.CallArgs{
290+
ContractABI: contract.ABI,
291+
MethodName: "someMethod",
292+
Args: []interface{}{arg1, arg2},
293+
}
294+
295+
// New:
296+
callArgs := testutiltypes.CallArgs{
297+
ContractABI: contract.ABI,
298+
MethodName: "someMethod",
299+
Args: []interface{}{arg1, arg2},
300+
Method: &SomeCall{Arg1: arg1, Arg2: arg2}, // Add this
301+
}
302+
```
303+
207304
## References
208305

209306
- Bank precompile migration: `tests/integration/precompiles/bank/`
307+
- Bech32 precompile migration: `tests/integration/precompiles/bech32/`
308+
- Slashing precompile migration: `tests/integration/precompiles/slashing/test_query.go`
210309
- go-abi library: github.com/yihuang/go-abi
211310
- Generated types example: `precompiles/bank/bank.abi.go`

0 commit comments

Comments
 (0)