-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathaddressGenerator_test.go
More file actions
81 lines (60 loc) · 2.18 KB
/
addressGenerator_test.go
File metadata and controls
81 lines (60 loc) · 2.18 KB
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
package addressGenerator
import (
"bytes"
"encoding/hex"
"fmt"
"testing"
"github.com/ElrondNetwork/elrond-go-core/core/check"
"github.com/ElrondNetwork/elrond-go-core/core/mock"
"github.com/ElrondNetwork/elrond-go-core/core/pubkeyConverter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// AddressBytesLen represents the number of bytes of an address
const AddressBytesLen = 32
var AddressPublicKeyConverter, _ = pubkeyConverter.NewBech32PubkeyConverter(AddressBytesLen, &mock.LoggerMock{})
func TestBlockChainHookImpl_NewAddressLengthNoGood(t *testing.T) {
t.Parallel()
ag, err := NewAddressGenerator(AddressPublicKeyConverter)
require.Nil(t, err)
assert.False(t, check.IfNil(ag))
address := []byte("test")
nonce := uint64(10)
scAddress, err := ag.NewAddress(address, nonce, []byte("00"))
assert.Equal(t, ErrAddressLengthNotCorrect, err)
assert.Nil(t, scAddress)
address = []byte("1234567890123456789012345678901234567890")
scAddress, err = ag.NewAddress(address, nonce, []byte("00"))
assert.Equal(t, ErrAddressLengthNotCorrect, err)
assert.Nil(t, scAddress)
}
func TestBlockChainHookImpl_NewAddressVMTypeTooLong(t *testing.T) {
t.Parallel()
ag, err := NewAddressGenerator(AddressPublicKeyConverter)
require.Nil(t, err)
address := []byte("01234567890123456789012345678900")
nonce := uint64(10)
vmType := []byte("010")
scAddress, err := ag.NewAddress(address, nonce, vmType)
assert.Equal(t, ErrVMTypeLengthIsNotCorrect, err)
assert.Nil(t, scAddress)
}
func TestBlockChainHookImpl_NewAddress(t *testing.T) {
t.Parallel()
ag, err := NewAddressGenerator(AddressPublicKeyConverter)
require.Nil(t, err)
address := []byte("01234567890123456789012345678900")
nonce := uint64(10)
vmType := []byte("11")
scAddress1, err := ag.NewAddress(address, nonce, vmType)
assert.Nil(t, err)
for i := 0; i < 8; i++ {
assert.Equal(t, scAddress1[i], uint8(0))
}
assert.True(t, bytes.Equal(vmType, scAddress1[8:10]))
nonce++
scAddress2, err := ag.NewAddress(address, nonce, []byte("00"))
assert.Nil(t, err)
assert.False(t, bytes.Equal(scAddress1, scAddress2))
fmt.Printf("%s \n%s \n", hex.EncodeToString(scAddress1), hex.EncodeToString(scAddress2))
}