github.com/0xsequence/ethkit@v1.25.0/ethtest/testchain_test.go (about) 1 package ethtest_test 2 3 import ( 4 "math/big" 5 "testing" 6 7 "github.com/0xsequence/ethkit/ethcoder" 8 "github.com/0xsequence/ethkit/ethtest" 9 "github.com/0xsequence/ethkit/go-ethereum/core/types" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 // yes, we even have to test the testutil 14 15 var ( 16 testchain *ethtest.Testchain 17 ) 18 19 func init() { 20 var err error 21 testchain, err = ethtest.NewTestchain() 22 if err != nil { 23 panic(err) 24 } 25 } 26 27 func TestTestchainID(t *testing.T) { 28 assert.Equal(t, testchain.ChainID().Uint64(), uint64(1337)) 29 } 30 31 func TestContractHelpers(t *testing.T) { 32 callmockContract, receipt := testchain.Deploy(t, "CallReceiverMock") 33 assert.NotNil(t, callmockContract) 34 assert.NotNil(t, receipt) 35 36 // Update contract value on CallReceiver by calling 'testCall' contract function 37 receipt, err := ethtest.ContractTransact( 38 testchain.MustWallet(2), 39 callmockContract.Address, callmockContract.ABI, 40 "testCall", big.NewInt(143), ethcoder.MustHexDecode("0x112233"), 41 ) 42 assert.NoError(t, err) 43 assert.NotNil(t, receipt) 44 assert.Equal(t, types.ReceiptStatusSuccessful, receipt.Status) 45 46 // Query the value ensuring its been updated on-chain 47 ret, err := ethtest.ContractQuery(testchain.Provider, callmockContract.Address, "lastValA()", "uint256", nil) 48 assert.NoError(t, err) 49 assert.Equal(t, []string{"143"}, ret) 50 51 // Query the value using different method, where we unpack the value 52 var result *big.Int 53 _, err = ethtest.ContractCall(testchain.Provider, callmockContract.Address, callmockContract.ABI, &result, "lastValA") 54 assert.NoError(t, err) 55 assert.Equal(t, uint64(143), result.Uint64()) 56 }