-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathenv_config_test.go
90 lines (84 loc) · 2.39 KB
/
env_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
package c_polygonid
import (
"testing"
"github.com/ethereum/go-ethereum/common"
core "github.com/iden3/go-iden3-core/v2"
"github.com/stretchr/testify/require"
)
func TestNewEnvConfigFromJSON(t *testing.T) {
cfgJSON := `{
"reverseHashServiceUrl": "http://localhost:8003",
"ipfsNodeUrl": "http://localhost:5001",
"chainConfigs": {
"1": {
"rpcUrl": "http://localhost:8545",
"stateContractAddr": "0xEA9aF2088B4a9770fC32A12fD42E61BDD317E655"
},
"0x10": {
"rpcUrl": "http://localhost:8546",
"stateContractAddr": "0xEA9aF2088B4a9770fC32A12fD42E61BDD317E655"
},
"0X2835": {
"rpcUrl": "http://localhost:8547",
"stateContractAddr": "0xEA9aF2088B4a9770fC32A12fD42E61BDD317E655"
}
},
"didMethods": [
{
"name": "ethr",
"blockchain": "ethereum",
"network": "mainnet",
"networkFlag": 6,
"methodByte": "0b010011",
"chainID": "10293"
}
]
}`
cfg, err := NewEnvConfigFromJSON([]byte(cfgJSON))
require.NoError(t, err)
require.Equal(t,
EnvConfig{
DIDMethods: []MethodConfig{
{
MethodName: "ethr",
Blockchain: "ethereum",
NetworkID: "mainnet",
NetworkFlag: 6,
MethodByte: 19,
ChainID: 10293,
},
},
ChainConfigs: PerChainConfig{
1: {
RPCUrl: "http://localhost:8545",
StateContractAddr: common.HexToAddress("0xEA9aF2088B4a9770fC32A12fD42E61BDD317E655"),
},
16: {
RPCUrl: "http://localhost:8546",
StateContractAddr: common.HexToAddress("0xEA9aF2088B4a9770fC32A12fD42E61BDD317E655"),
},
10293: {
RPCUrl: "http://localhost:8547",
StateContractAddr: common.HexToAddress("0xEA9aF2088B4a9770fC32A12fD42E61BDD317E655"),
},
},
IPFSNodeURL: "http://localhost:5001",
},
cfg)
// check that custom DID methods are registered
chainID, err := core.GetChainID("ethereum", "mainnet")
require.NoError(t, err)
require.Equal(t, core.ChainID(10293), chainID)
blockchain, networkID, err := core.NetworkByChainID(core.ChainID(10293))
require.NoError(t, err)
require.Equal(t, core.Blockchain("ethereum"), blockchain)
require.Equal(t, core.NetworkID("mainnet"), networkID)
}
func TestNewEnvConfigFromJSON_cacheDir(t *testing.T) {
cfgJSON := `{
"cacheDir": "/var/cache"
}`
cfg, err := NewEnvConfigFromJSON([]byte(cfgJSON))
require.NoError(t, err)
require.Equal(t, "/var/cache", cfg.CacheDir)
}