-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check decoding params for new methods
- Loading branch information
Geoff Stuart
committed
Feb 1, 2023
1 parent
27465e5
commit b3653f3
Showing
3 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// stm: #integration | ||
package itests | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/filecoin-project/go-state-types/abi" | ||
actorstypes "github.com/filecoin-project/go-state-types/actors" | ||
"github.com/filecoin-project/go-state-types/builtin" | ||
"github.com/filecoin-project/go-state-types/manifest" | ||
|
||
"github.com/filecoin-project/lotus/build" | ||
"github.com/filecoin-project/lotus/chain/actors" | ||
"github.com/filecoin-project/lotus/cli" | ||
) | ||
|
||
type testCase struct { | ||
ActorKey string | ||
MethodNum abi.MethodNum | ||
Bytestr string | ||
} | ||
|
||
// Used './lotus state replay --show-trace <msg-cid>' to get params/return to decode. | ||
func TestDecodeParams(t *testing.T) { | ||
testCases := []testCase{ | ||
{ | ||
ActorKey: manifest.EvmKey, | ||
MethodNum: builtin.MethodsEVM.InvokeContract, | ||
Bytestr: "58a4d4a0cd0a000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000028000181e20392202034194f3b7cae3042a57b63ea4c36a962478e41bfa8ddc80dd61cae8bebdedf23000000000000000000000000000000000000000000000000", | ||
}, | ||
{ | ||
ActorKey: manifest.EamKey, | ||
MethodNum: builtin.MethodsEAM.CreateExternal, | ||
Bytestr: "590dde608060405234801561001057600080fd5b5061002d61002261003260201b60201c565b61003a60201b60201c565b6100fe565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b610cd18061010d6000396000f3fe6080604052600436106100555760003560e01c806305b03ef81461005a5780635a73b0bf14610097578063715018a6146100c05780638da5cb5b146100d7578063a26e118614610102578063f2fde38b1461011e575b600080fd5b34801561006657600080fd5b50610081600480360381019061007c91906106ec565b610147565b60405161008e9190610978565b60405180910390f35b3480156100a357600080fd5b506100be60048036038101906100b99190610748565b610182565b005b3480156100cc57600080fd5b506100d5610321565b005b3480156100e357600080fd5b506100ec610335565b6040516100f991906108bf565b60405180910390f35b61011c600480360381019061011791906106a3565b61035e565b005b34801561012a57600080fd5b5061014560048036038101906101409190610676565b61040e565b005b600182805160208101820180518482526020830160208501208183528095505050505050602052806000526040600020600091509150505481565b61018a610492565b8060018460405161019b91906108a8565b908152602001604051809103902060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610228576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161021f90610938565b60405180910390fd5b8060018460405161023991906108a8565b908152602001604051809103902060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546102939190610a66565b925050819055503373ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f193505050501580156102e0573d6000803e3d6000fd5b507f901c03da5d88eb3d62ab4617e7b7d17d86db16356823a7971127d5181a842fef828483604051610314939291906108da565b60405180910390a1505050565b610329610492565b6103336000610510565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b3460018260405161036f91906108a8565b908152602001604051809103902060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546103c99190610a10565b925050819055507f2d4b597935f3cd67fb2eebf1db4debc934cee5c7baa7153f980fdbeb2e74084e338234604051610403939291906108da565b60405180910390a150565b610416610492565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610486576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047d90610918565b60405180910390fd5b61048f81610510565b50565b61049a6105d4565b73ffffffffffffffffffffffffffffffffffffffff166104b8610335565b73ffffffffffffffffffffffffffffffffffffffff161461050e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161050590610958565b60405180910390fd5b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600033905090565b60006105ef6105ea846109b8565b610993565b90508281526020810184848401111561060b5761060a610bac565b5b610616848285610ad6565b509392505050565b60008135905061062d81610c6d565b92915050565b600082601f83011261064857610647610ba7565b5b81356106588482602086016105dc565b91505092915050565b60008135905061067081610c84565b92915050565b60006020828403121561068c5761068b610bb6565b5b600061069a8482850161061e565b91505092915050565b6000602082840312156106b9576106b8610bb6565b5b600082013567ffffffffffffffff8111156106d7576106d6610bb1565b5b6106e384828501610633565b91505092915050565b6000806040838503121561070357610702610bb6565b5b600083013567ffffffffffffffff81111561072157610720610bb1565b5b61072d85828601610633565b925050602061073e8582860161061e565b9150509250929050565b60008060006060848603121561076157610760610bb6565b5b600084013567ffffffffffffffff81111561077f5761077e610bb1565b5b61078b86828701610633565b935050602061079c8682870161061e565b92505060406107ad86828701610661565b9150509250925092565b6107c081610a9a565b82525050565b60006107d1826109e9565b6107db81856109f4565b93506107eb818560208601610ae5565b6107f481610bbb565b840191505092915050565b600061080a826109e9565b6108148185610a05565b9350610824818560208601610ae5565b80840191505092915050565b600061083d6026836109f4565b915061084882610bcc565b604082019050919050565b6000610860600f836109f4565b915061086b82610c1b565b602082019050919050565b60006108836020836109f4565b915061088e82610c44565b602082019050919050565b6108a281610acc565b82525050565b60006108b482846107ff565b915081905092915050565b60006020820190506108d460008301846107b7565b92915050565b60006060820190506108ef60008301866107b7565b818103602083015261090181856107c6565b90506109106040830184610899565b949350505050565b6000602082019050818103600083015261093181610830565b9050919050565b6000602082019050818103600083015261095181610853565b9050919050565b6000602082019050818103600083015261097181610876565b9050919050565b600060208201905061098d6000830184610899565b92915050565b600061099d6109ae565b90506109a98282610b18565b919050565b6000604051905090565b600067ffffffffffffffff8211156109d3576109d2610b78565b5b6109dc82610bbb565b9050602081019050919050565b600081519050919050565b600082825260208201905092915050565b600081905092915050565b6000610a1b82610acc565b9150610a2683610acc565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610a5b57610a5a610b49565b5b828201905092915050565b6000610a7182610acc565b9150610a7c83610acc565b925082821015610a8f57610a8e610b49565b5b828203905092915050565b6000610aa582610aac565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b83811015610b03578082015181840152602081019050610ae8565b83811115610b12576000848401525b50505050565b610b2182610bbb565b810181811067ffffffffffffffff82111715610b4057610b3f610b78565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f62616c616e636520746f6f206c6f770000000000000000000000000000000000600082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b610c7681610a9a565b8114610c8157600080fd5b50565b610c8d81610acc565b8114610c9857600080fd5b5056fea2646970667358221220bdef2e63f4a80f250df77d0955fb43ff301f5a632865a02ac71cdc94ded8edd964736f6c63430008070033", | ||
}, | ||
} | ||
|
||
for _, _tc := range testCases { | ||
tc := _tc | ||
t.Run(tc.ActorKey+" "+tc.MethodNum.String(), func(t *testing.T) { | ||
av, err := actorstypes.VersionForNetwork(build.TestNetworkVersion) | ||
require.NoError(t, err) | ||
actorCodeCid, found := actors.GetActorCodeID(av, tc.ActorKey) | ||
require.True(t, found) | ||
|
||
params, err := hex.DecodeString(tc.Bytestr) | ||
require.NoError(t, err) | ||
|
||
paramString, err := cli.JsonParams(actorCodeCid, tc.MethodNum, params) | ||
require.NoError(t, err) | ||
|
||
fmt.Println(paramString) | ||
}) | ||
} | ||
} | ||
|
||
func TestDecodeReturn(t *testing.T) { | ||
testCases := []testCase{ | ||
{ | ||
ActorKey: manifest.EvmKey, | ||
MethodNum: builtin.MethodsEVM.InvokeContract, | ||
Bytestr: "5820000000000000000000000000000000000000000000000000000000000000002d", | ||
}, | ||
{ | ||
ActorKey: manifest.EamKey, | ||
MethodNum: builtin.MethodsEAM.CreateExternal, | ||
Bytestr: "8319195b5502ff4af64187327799171354df10b4b3bfc2e4c30654922d6956c99e12dfeb3224dea977d0939758a1fe", | ||
}, | ||
} | ||
|
||
for _, _tc := range testCases { | ||
tc := _tc | ||
t.Run(tc.ActorKey+" "+tc.MethodNum.String(), func(t *testing.T) { | ||
av, err := actorstypes.VersionForNetwork(build.TestNetworkVersion) | ||
require.NoError(t, err) | ||
actorCodeCid, found := actors.GetActorCodeID(av, tc.ActorKey) | ||
require.True(t, found) | ||
|
||
ret, err := hex.DecodeString(tc.Bytestr) | ||
require.NoError(t, err) | ||
|
||
paramString, err := cli.JsonReturn(actorCodeCid, tc.MethodNum, ret) | ||
require.NoError(t, err) | ||
|
||
fmt.Println(paramString) | ||
}) | ||
} | ||
} |