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