-
Notifications
You must be signed in to change notification settings - Fork 0
/
ethabi_test.go
47 lines (37 loc) · 1.51 KB
/
ethabi_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
package ethabi
import (
"testing"
goEthereumAbi "github.com/ethereum/go-ethereum/accounts/abi"
"github.com/stretchr/testify/assert"
)
func TestParsingEventAbis(t *testing.T) {
humanReadableAbis := []string{
"event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)",
"event Transfer(address indexed from, address indexed to, uint256 tokenId)",
"event Transfer(address indexed from, address indexed to, uint256 tokenId)",
"event Transfer(address indexed from, address indexed to, uint256 tokenId)",
}
for _, abi := range humanReadableAbis {
abi, err := ParseABI(&abi)
assert.Nil(t, err)
assert.Equal(t, abi.Events["Transfer"].Sig, "Transfer(address,address,uint256)")
}
}
func TestNormalizesUIntTypeWhenParsing(t *testing.T) {
abi := "event Transfer(address indexed from, address indexed to, uint indexed tokenId)"
parsedABI, err := ParseABI(&abi)
assert.Nil(t, err)
assert.Equal(t, parsedABI.Events["Transfer"].Sig, "Transfer(address,address,uint256)")
}
func TestParsingNonEventAbis(t *testing.T) {
invalidHumanReadableAbi := "contract SampleContract{}"
abi, err := ParseABI(&invalidHumanReadableAbi)
assert.NotNil(t, err)
assert.Equal(t, abi, goEthereumAbi.ABI{})
}
func TestGetABIName(t *testing.T) {
abi1 := "event Transfer(address indexed from, address indexed to, uint tokens)"
abi2 := "event Approval(address indexed tokenOwner, address indexed spender, uint tokens)"
assert.Equal(t, GetABIName(&abi1), "Transfer")
assert.Equal(t, GetABIName(&abi2), "Approval")
}