-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathaddress_test.go
More file actions
96 lines (79 loc) · 2.71 KB
/
address_test.go
File metadata and controls
96 lines (79 loc) · 2.71 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package database
import (
"strconv"
"testing"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/dapplink-labs/multichain-sync-account/common/json2"
)
func TestAddressesDB_StoreAndQuery(t *testing.T) {
const (
CurrentRequestId = 1
CurrentChainId = 17000
CurrentChain = "ethereum"
)
db := SetupDb()
addressesDB := NewAddressesDB(db.gorm)
address := &Addresses{
GUID: uuid.New(),
Address: common.HexToAddress("0x1234567890abcdef1234567890abcdef12345678"),
AddressType: AddressTypeUser,
PublicKey: "public_key_example",
Timestamp: uint64(time.Now().Unix()),
}
err := addressesDB.StoreAddresses(strconv.Itoa(CurrentRequestId), []*Addresses{address})
if err != nil {
t.Errorf("Failed to store balances: %v", err)
}
// Test AddressExist
exists, addrType := addressesDB.AddressExist(strconv.Itoa(CurrentRequestId), &address.Address)
assert.True(t, exists)
assert.Equal(t, AddressTypeUser, addrType)
// Test QueryAddressesByToAddress
result, err := addressesDB.QueryAddressesByToAddress(strconv.Itoa(CurrentRequestId), &address.Address)
assert.NoError(t, err)
assert.NotNil(t, result)
t.Logf("result %v", json2.ToPrettyJSON(result))
// Test GetAllAddresses
allAddresses, err := addressesDB.GetAllAddresses(strconv.Itoa(CurrentRequestId))
assert.NoError(t, err)
assert.Len(t, allAddresses, 1)
t.Logf("result %v", json2.ToPrettyJSON(allAddresses))
}
func TestAddressesDB_QueryHotAndColdWalletInfo(t *testing.T) {
const (
CurrentRequestId = 1
CurrentChainId = 17000
CurrentChain = "ethereum"
)
db := SetupDb()
addressesDB := NewAddressesDB(db.gorm)
hotAddress := &Addresses{
GUID: uuid.New(),
Address: common.HexToAddress("0xabcdefabcdefabcdefabcdefabcdefabcde1"),
AddressType: AddressTypeHot,
PublicKey: "hot_public_key",
Timestamp: uint64(time.Now().Unix()),
}
coldAddress := &Addresses{
GUID: uuid.New(),
Address: common.HexToAddress("0xabcdefabcdefabcdefabcdefabcdefabcde2"),
AddressType: AddressTypeCold,
PublicKey: "cold_public_key",
Timestamp: uint64(time.Now().Unix()),
}
err := addressesDB.StoreAddresses(strconv.Itoa(CurrentRequestId), []*Addresses{hotAddress, coldAddress})
assert.NoError(t, err)
// Test QueryHotWalletInfo
hotResult, err := addressesDB.QueryHotWalletInfo(strconv.Itoa(CurrentRequestId))
assert.NoError(t, err)
assert.NotNil(t, hotResult)
t.Logf("hotResult %v", json2.ToPrettyJSON(hotResult))
// Test QueryColdWalletInfo
coldResult, err := addressesDB.QueryColdWalletInfo(strconv.Itoa(CurrentRequestId))
assert.NoError(t, err)
assert.NotNil(t, coldResult)
t.Logf("coldResult %v", json2.ToPrettyJSON(coldResult))
}