This repository has been archived by the owner on May 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 346
/
events.go
84 lines (67 loc) · 2.22 KB
/
events.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 test
import (
"context"
"testing"
"github.com/hyperledger/burrow/crypto"
"github.com/hyperledger/burrow/execution/evm/abi"
"github.com/hyperledger/burrow/execution/exec"
"github.com/hyperledger/burrow/rpc/rpctransact"
"github.com/hyperledger/burrow/txs/payload"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
)
func NewTransactClient(t testing.TB, listenAddress string) rpctransact.TransactClient {
t.Helper()
conn, err := grpc.Dial(listenAddress, grpc.WithInsecure())
require.NoError(t, err)
return rpctransact.NewTransactClient(conn)
}
func CreateContract(t testing.TB, cli rpctransact.TransactClient, inputAddress crypto.Address) *exec.TxExecution {
t.Helper()
txe, err := cli.CallTxSync(context.Background(), &payload.CallTx{
Input: &payload.TxInput{
Address: inputAddress,
Amount: 2,
},
Address: nil,
Data: Bytecode_EventsTest,
Fee: 2,
GasLimit: 10000,
})
require.NoError(t, err)
if txe.Exception != nil {
t.Fatalf("call should not generate exception but returned: %v", txe.Exception.Error())
}
return txe
}
func CallRemoveEvent(t testing.TB, cli rpctransact.TransactClient, inputAddress, contractAddress crypto.Address,
name string) *exec.TxExecution {
return Call(t, cli, inputAddress, contractAddress, "removeThing", name)
}
func CallAddEvent(t testing.TB, cli rpctransact.TransactClient, inputAddress, contractAddress crypto.Address,
name, description string) *exec.TxExecution {
return Call(t, cli, inputAddress, contractAddress, "addThing", name, description)
}
func Call(t testing.TB, cli rpctransact.TransactClient, inputAddress, contractAddress crypto.Address,
functionName string, args ...interface{}) *exec.TxExecution {
t.Helper()
spec, err := abi.ReadAbiSpec(Abi_EventsTest)
require.NoError(t, err)
data, _, err := spec.Pack(functionName, args...)
require.NoError(t, err)
txe, err := cli.CallTxSync(context.Background(), &payload.CallTx{
Input: &payload.TxInput{
Address: inputAddress,
Amount: 2,
},
Address: &contractAddress,
Data: data,
Fee: 2,
GasLimit: 1000000,
})
require.NoError(t, err)
if txe.Exception != nil {
t.Fatalf("call should not generate exception but returned: %v", txe.Exception.Error())
}
return txe
}