forked from 0xakk0r0kamui/constant-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunified_config_test.go
97 lines (83 loc) · 2.98 KB
/
unified_config_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
96
97
package main
import (
"bytes"
"fmt"
"os"
"testing"
"github.com/incognitochain/incognito-chain/blockchain/bridgeagg"
"github.com/incognitochain/incognito-chain/config"
"github.com/incognitochain/incognito-chain/dataaccessobject/rawdbv2"
"github.com/incognitochain/incognito-chain/metadata/rpccaller"
"github.com/incognitochain/incognito-chain/rpcserver/jsonresult"
)
func TestUnifiedTokenFile(t *testing.T) {
// set network to testnet2
os.Setenv(config.NetworkKey, config.TestNetNetwork)
os.Setenv(config.NetworkVersionKey, config.TestNetVersion2)
// read file default path config/mainnet/unified_token.json
config.LoadUnifiedToken([]byte{})
// call API get list privacy tokens:
incClient := rpccaller.NewRPCClient()
// host := "https://mainnet.incognito.org/fullnode"
host := "https://testnet.incognito.org/fullnode"
method := "listprivacycustomtoken"
method2 := "getallbridgetokens"
params := []string{}
type Resp struct {
Result jsonresult.ListCustomToken
Error error
}
resp := Resp{}
err := incClient.RPCCall("", host, "", method, params, &resp)
fmt.Printf("Err call get list pTokens: %v\n", err)
// fmt.Printf("List ptoken: %+v\n", resp.Result)
pTokens := resp.Result.ListCustomToken
type Resp2 struct {
Result []*rawdbv2.BridgeTokenInfo
Error error
}
resp2 := Resp2{}
err = incClient.RPCCall("", host, "", method2, params, &resp2)
fmt.Printf("Err call get list bridge Tokens: %v\n", err)
fmt.Printf("List bridge token: %+v\n", resp2.Result)
bridgeTokens := resp2.Result
for _, unifiedTokens := range config.UnifiedToken() {
for unifiedTokenID, vaults := range unifiedTokens {
// unifiedTokenID must not exist
for _, pToken := range pTokens {
if pToken.ID == unifiedTokenID.String() {
fmt.Errorf("unifiedTokenID is exist: %v\n", unifiedTokenID)
break
}
}
// vaults: incTokenID and externalTokenID must matching
for incTokenID, v := range vaults {
// get expected external token ID from list pTokens
expectedExtTokenID := []byte{}
isExistIncTokenID := false
for _, pToken := range bridgeTokens {
if pToken.TokenID.String() == incTokenID.String() {
expectedExtTokenID = pToken.ExternalTokenID
isExistIncTokenID = true
break
}
}
actualExtTokenID, _ := bridgeagg.GetExternalTokenIDByNetworkID(v.ExternalTokenID, v.NetworkID)
if !isExistIncTokenID {
fmt.Printf("IncTokenID is not exist: %v\n", incTokenID.String())
// TODO: must check external token is not exist
for _, pToken := range bridgeTokens {
if bytes.Equal(pToken.ExternalTokenID, actualExtTokenID) {
fmt.Errorf("IncTokenID is not exist, but externalTokenID is exist: %v - %v", incTokenID.String(), v.ExternalTokenID)
break
}
}
} else {
if !bytes.Equal(expectedExtTokenID, actualExtTokenID) {
fmt.Errorf("invalid external token id: unifiedTokenID %v - expectedExtTokenID %v - actualExtTokenID %v\n", unifiedTokenID, expectedExtTokenID, actualExtTokenID)
}
}
}
}
}
}