github.com/Tri-stone/burrow@v0.25.0/vent/test/events.go (about) 1 package test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/hyperledger/burrow/crypto" 8 "github.com/hyperledger/burrow/execution/evm/abi" 9 "github.com/hyperledger/burrow/execution/exec" 10 "github.com/hyperledger/burrow/rpc/rpctransact" 11 "github.com/hyperledger/burrow/txs/payload" 12 "github.com/stretchr/testify/require" 13 "google.golang.org/grpc" 14 ) 15 16 func NewTransactClient(t testing.TB, listenAddress string) rpctransact.TransactClient { 17 t.Helper() 18 19 conn, err := grpc.Dial(listenAddress, grpc.WithInsecure()) 20 require.NoError(t, err) 21 return rpctransact.NewTransactClient(conn) 22 } 23 24 func CreateContract(t testing.TB, cli rpctransact.TransactClient, inputAddress crypto.Address) *exec.TxExecution { 25 t.Helper() 26 27 txe, err := cli.CallTxSync(context.Background(), &payload.CallTx{ 28 Input: &payload.TxInput{ 29 Address: inputAddress, 30 Amount: 2, 31 }, 32 Address: nil, 33 Data: Bytecode_EventsTest, 34 Fee: 2, 35 GasLimit: 10000, 36 }) 37 require.NoError(t, err) 38 39 if txe.Exception != nil { 40 t.Fatalf("call should not generate exception but returned: %v", txe.Exception.Error()) 41 } 42 43 return txe 44 } 45 46 func CallRemoveEvent(t testing.TB, cli rpctransact.TransactClient, inputAddress, contractAddress crypto.Address, 47 name string) *exec.TxExecution { 48 return Call(t, cli, inputAddress, contractAddress, "removeThing", name) 49 50 } 51 52 func CallAddEvent(t testing.TB, cli rpctransact.TransactClient, inputAddress, contractAddress crypto.Address, 53 name, description string) *exec.TxExecution { 54 return Call(t, cli, inputAddress, contractAddress, "addThing", name, description) 55 } 56 57 func Call(t testing.TB, cli rpctransact.TransactClient, inputAddress, contractAddress crypto.Address, 58 functionName string, args ...interface{}) *exec.TxExecution { 59 t.Helper() 60 61 spec, err := abi.ReadAbiSpec(Abi_EventsTest) 62 require.NoError(t, err) 63 64 data, _, err := spec.Pack(functionName, args...) 65 require.NoError(t, err) 66 67 txe, err := cli.CallTxSync(context.Background(), &payload.CallTx{ 68 Input: &payload.TxInput{ 69 Address: inputAddress, 70 Amount: 2, 71 }, 72 Address: &contractAddress, 73 Data: data, 74 Fee: 2, 75 GasLimit: 1000000, 76 }) 77 require.NoError(t, err) 78 79 if txe.Exception != nil { 80 t.Fatalf("call should not generate exception but returned: %v", txe.Exception.Error()) 81 } 82 83 return txe 84 }