-
Notifications
You must be signed in to change notification settings - Fork 4
/
address_test.go
95 lines (70 loc) · 3.1 KB
/
address_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
85
86
87
88
89
90
91
92
93
94
95
package vmcommon
import (
"encoding/hex"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAddress_isSmartContractAddress(t *testing.T) {
t.Parallel()
address, _ := hex.DecodeString("12345")
assert.False(t, IsSmartContractAddress(address))
address, _ = hex.DecodeString("000000000001000000005fed9c659422cd8429ce92f8973bba2a9fb51e0eb3a1")
assert.False(t, IsSmartContractAddress(address))
scaddress, _ := hex.DecodeString("000000000000000000005fed9c659422cd8429ce92f8973bba2a9fb51e0eb3a1")
assert.True(t, IsSmartContractAddress(scaddress))
emAddress, _ := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000000")
assert.True(t, IsSmartContractAddress(emAddress))
}
func TestAddress_IsMetachainIdentifier(t *testing.T) {
t.Parallel()
identifier := make([]byte, 0)
assert.False(t, IsMetachainIdentifier(identifier))
identifier, _ = hex.DecodeString("001234567801000000005fed9c659422cd8429ce92f8973bba2a9fb51e0eb3a1")
assert.False(t, IsMetachainIdentifier(identifier))
identifier, _ = hex.DecodeString("ff")
assert.True(t, IsMetachainIdentifier(identifier))
}
func TestIsSmartContractOnMetachain_ScAddressTooShortShouldReturnFalse(t *testing.T) {
t.Parallel()
identifier, _ := hex.DecodeString("ff")
scAddress, _ := hex.DecodeString("000000000000eb3a1")
assert.False(t, IsSmartContractOnMetachain(identifier, scAddress))
}
func TestIsSmartContractOnMetachain_IdentifierNotMetaShouldReturnFalse(t *testing.T) {
t.Parallel()
identifier, _ := hex.DecodeString("aa")
scAddress, _ := hex.DecodeString("00000000000000000000000000000022cd8429ce92f8973bba2a9fb51e0eb3a1")
assert.False(t, IsSmartContractOnMetachain(identifier, scAddress))
}
func TestIsSmartContractOnMetachain_AddressIsNotSCShouldReturnFalse(t *testing.T) {
t.Parallel()
identifier, _ := hex.DecodeString("ff")
scAddress, _ := hex.DecodeString("000000000001000000005fed9c659422cd8429ce92f8973bba2a9fb51e0eb3a1")
assert.False(t, IsSmartContractOnMetachain(identifier, scAddress))
}
func TestIsSmartContractOnMetachain_ShouldReturnFalse(t *testing.T) {
t.Parallel()
identifier, _ := hex.DecodeString("ff")
scAddress, _ := hex.DecodeString("000000000000000000005fed9c659422cd8429ce92f8973bba2a9fb51e0eb3a1")
assert.False(t, IsSmartContractOnMetachain(identifier, scAddress))
}
func TestIsSmartContractOnMetachain_ShouldReturnTrue(t *testing.T) {
t.Parallel()
identifier, _ := hex.DecodeString("ff")
scAddress, _ := hex.DecodeString("000000000000000000000000000000000000000000000000000000b51e0eb3a1")
assert.True(t, IsSmartContractOnMetachain(identifier, scAddress))
}
func Test_ParseVMTypeFromContractAddress_Ok(t *testing.T) {
t.Parallel()
identifier, _ := hex.DecodeString("0a0b")
scAddress, _ := hex.DecodeString("00000000000000000a0b5fed9c659422cd8429ce92f8973bba2a9fb51e0eb3a1")
vmType, _ := ParseVMTypeFromContractAddress(scAddress)
assert.Equal(t, identifier, vmType)
}
func Test_ParseVMTypeFromContractAddress_Invalid(t *testing.T) {
t.Parallel()
scAddress, _ := hex.DecodeString("12345")
vmType, err := ParseVMTypeFromContractAddress(scAddress)
assert.Nil(t, vmType)
assert.Equal(t, ErrInvalidVMType, err)
}