-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmethod_config_test.go
52 lines (46 loc) · 1.37 KB
/
method_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
package c_polygonid
import (
"encoding/json"
"testing"
core "github.com/iden3/go-iden3-core/v2"
"github.com/stretchr/testify/require"
)
func TestMethodConfig_UnmarshalJSON(t *testing.T) {
in := `{
"name": "ethr",
"blockchain": "ethereum",
"network": "mainnet",
"networkFlag": 6,
"methodByte": "0b010011",
"chainID": "10293"
}`
var methodCfg MethodConfig
err := json.Unmarshal([]byte(in), &methodCfg)
require.NoError(t, err)
require.Equal(t, core.DIDMethod("ethr"), methodCfg.MethodName)
require.Equal(t, core.Blockchain("ethereum"), methodCfg.Blockchain)
require.Equal(t, core.NetworkID("mainnet"), methodCfg.NetworkID)
require.Equal(t, byte(6), methodCfg.NetworkFlag)
require.Equal(t, byte(19), methodCfg.MethodByte)
require.Equal(t, core.ChainID(10293), methodCfg.ChainID)
in = `{
"blockchain": "ethereum",
"network": "mainnet",
"networkFlag": 6,
"methodByte": "0b010011",
"chainID": "10293"
}`
err = json.Unmarshal([]byte(in), &methodCfg)
require.EqualError(t, err, "method name is empty")
in = `{
"name": "ethr",
"blockchain": "ethereum",
"network": "mainnet",
"networkFlag": 6,
"methodByte": "0b010011",
"chainID": "0X123"
}`
err = json.Unmarshal([]byte(in), &methodCfg)
require.NoError(t, err)
require.Equal(t, core.ChainID(291), methodCfg.ChainID)
}