-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_deployment_test.go
84 lines (65 loc) · 3.69 KB
/
example_deployment_test.go
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package seth_test
import (
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"github.com/goplugin/plugin-testing-framework/seth"
network_debug_contract "github.com/goplugin/plugin-testing-framework/seth/contracts/bind/debug"
link_token "github.com/goplugin/plugin-testing-framework/seth/contracts/bind/link"
network_debug_sub_contract "github.com/goplugin/plugin-testing-framework/seth/contracts/bind/sub"
)
// Shows how to deploy a contract with parameterless constructor and bind it to it's Geth wrapper
func TestDeploymentParameterlessConstructorExample(t *testing.T) {
commonEnvVars(t)
c, err := seth.NewClient()
require.NoError(t, err, "failed to initialise seth")
contractData, err := c.DeployContractFromContractStore(c.NewTXOpts(), "NetworkDebugSubContract.abi")
require.NoError(t, err, "failed to deploy sub-debug contract")
contract, err := network_debug_sub_contract.NewNetworkDebugSubContract(contractData.Address, c.Client)
require.NoError(t, err, "failed to create debug contract instance")
_, err = c.Decode(contract.TraceOneInt(c.NewTXOpts(), big.NewInt(1)))
require.NoError(t, err, "failed to decode transaction")
}
// Shows how to deploy a contract with constructor with parameters and bind it to it's Geth wrapper
func TestDeploymentConstructorWithParametersExample(t *testing.T) {
commonEnvVars(t)
c, err := seth.NewClient()
require.NoError(t, err, "failed to initialise seth")
contractData, err := c.DeployContractFromContractStore(c.NewTXOpts(), "NetworkDebugSubContract.abi", common.Address{})
require.NoError(t, err, "failed to deploy debug contract")
contract, err := network_debug_contract.NewNetworkDebugContract(contractData.Address, c.Client)
require.NoError(t, err, "failed to create debug contract instance")
_, err = c.Decode(contract.ProcessUintArray(c.NewTXOpts(), []*big.Int{big.NewInt(1)}))
require.NoError(t, err, "failed to decode transaction")
}
// Shows how to deploy a contract with parameterless constructor that takes ABI and BIN from Geth wrapper
// and bind it to that wrapper
func TestDeploymentFromGethWrapperExample(t *testing.T) {
commonEnvVars(t)
c, err := seth.NewClient()
require.NoError(t, err, "failed to initialise seth")
abi, err := network_debug_contract.NetworkDebugContractMetaData.GetAbi()
require.NoError(t, err, "failed to get ABI")
contractData, err := c.DeployContract(c.NewTXOpts(), "NetworkDebugSubContract", *abi, common.FromHex(network_debug_contract.NetworkDebugContractBin))
require.NoError(t, err, "failed to deploy sub-debug contract from wrapper's ABI/BIN")
contract, err := network_debug_sub_contract.NewNetworkDebugSubContract(contractData.Address, c.Client)
require.NoError(t, err, "failed to create debug contract instance")
_, err = c.Decode(contract.TraceOneInt(c.NewTXOpts(), big.NewInt(1)))
require.NoError(t, err, "failed to decode transaction")
}
func TestDeploymentLinkTokenFromGethWrapperExample(t *testing.T) {
commonEnvVars(t)
c, err := seth.NewClient()
require.NoError(t, err, "failed to initialise seth")
abi, err := link_token.LinkTokenMetaData.GetAbi()
require.NoError(t, err, "failed to get ABI")
c.ContractStore.ABIs["LinkToken.abi"] = *abi
require.NoError(t, err, "failed to get ABI")
contractData, err := c.DeployContract(c.NewTXOpts(), "LinkToken", *abi, common.FromHex(link_token.LinkTokenMetaData.Bin))
require.NoError(t, err, "failed to deploy link token contract from wrapper's ABI/BIN")
contract, err := link_token.NewLinkToken(contractData.Address, c.Client)
require.NoError(t, err, "failed to create debug contract instance")
_, err = c.Decode(contract.Mint(c.NewTXOpts(), c.Addresses[0], big.NewInt(1)))
require.Error(t, err, "did not fail to mint tokens")
}