1- package ethcoder
1+ package ethcoder_test
22
33import (
44 "math/big"
55 "testing"
66
7+ "github.com/0xsequence/ethkit/ethcoder"
78 "github.com/0xsequence/ethkit/ethwallet"
89 "github.com/0xsequence/ethkit/go-ethereum/common"
910 "github.com/stretchr/testify/assert"
1011)
1112
1213func TestTypedDataTypes (t * testing.T ) {
13- types := TypedDataTypes {
14+ types := ethcoder. TypedDataTypes {
1415 "Person" : {
1516 {Name : "name" , Type : "string" },
1617 {Name : "wallet" , Type : "address" },
@@ -31,7 +32,7 @@ func TestTypedDataTypes(t *testing.T) {
3132 assert .Equal (t , "Person(string name,address wallet)" , encodeType )
3233
3334 typeHash , _ := types .TypeHash ("Person" )
34- typeHashHex := HexEncode (typeHash )
35+ typeHashHex := ethcoder . HexEncode (typeHash )
3536 assert .Equal (t , "0xb9d8c78acf9b987311de6c7b45bb6a9c8e1bf361fa7fd3467a2163f994c79500" , typeHashHex )
3637
3738 encodeType , err = types .EncodeType ("Mail" )
@@ -42,8 +43,8 @@ func TestTypedDataTypes(t *testing.T) {
4243func TestTypedDataCase1 (t * testing.T ) {
4344 verifyingContract := common .HexToAddress ("0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC" )
4445
45- typedData := & TypedData {
46- Types : TypedDataTypes {
46+ typedData := & ethcoder. TypedData {
47+ Types : ethcoder. TypedDataTypes {
4748 "EIP712Domain" : {
4849 {Name : "name" , Type : "string" },
4950 {Name : "version" , Type : "string" },
@@ -56,7 +57,7 @@ func TestTypedDataCase1(t *testing.T) {
5657 },
5758 },
5859 PrimaryType : "Person" ,
59- Domain : TypedDataDomain {
60+ Domain : ethcoder. TypedDataDomain {
6061 Name : "Ether Mail" ,
6162 Version : "1" ,
6263 ChainID : big .NewInt (1 ),
@@ -69,13 +70,13 @@ func TestTypedDataCase1(t *testing.T) {
6970 },
7071 }
7172
72- domainHash , err := typedData .hashStruct ("EIP712Domain" , typedData .Domain .Map ())
73+ domainHash , err := typedData .HashStruct ("EIP712Domain" , typedData .Domain .Map ())
7374 assert .NoError (t , err )
74- assert .Equal (t , "0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f" , HexEncode (domainHash ))
75+ assert .Equal (t , "0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f" , ethcoder . HexEncode (domainHash ))
7576
7677 digest , err := typedData .EncodeDigest ()
7778 assert .NoError (t , err )
78- assert .Equal (t , "0x0a94cf6625e5860fc4f330d75bcd0c3a4737957d2321d1a024540ab5320fe903" , HexEncode (digest ))
79+ assert .Equal (t , "0x0a94cf6625e5860fc4f330d75bcd0c3a4737957d2321d1a024540ab5320fe903" , ethcoder . HexEncode (digest ))
7980
8081 // fmt.Println("===> digest", HexEncode(digest))
8182
@@ -84,7 +85,7 @@ func TestTypedDataCase1(t *testing.T) {
8485 assert .NoError (t , err )
8586
8687 ethSigedTypedData , err := wallet .SignMessage ([]byte (digest ))
87- ethSigedTypedDataHex := HexEncode (ethSigedTypedData )
88+ ethSigedTypedDataHex := ethcoder . HexEncode (ethSigedTypedData )
8889 assert .NoError (t , err )
8990
9091 assert .Equal (t ,
@@ -101,8 +102,8 @@ func TestTypedDataCase1(t *testing.T) {
101102func TestTypedDataCase2 (t * testing.T ) {
102103 verifyingContract := common .HexToAddress ("0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC" )
103104
104- typedData := & TypedData {
105- Types : TypedDataTypes {
105+ typedData := & ethcoder. TypedData {
106+ Types : ethcoder. TypedDataTypes {
106107 "EIP712Domain" : {
107108 {Name : "name" , Type : "string" },
108109 {Name : "version" , Type : "string" },
@@ -116,7 +117,7 @@ func TestTypedDataCase2(t *testing.T) {
116117 },
117118 },
118119 PrimaryType : "Person" ,
119- Domain : TypedDataDomain {
120+ Domain : ethcoder. TypedDataDomain {
120121 Name : "Ether Mail" ,
121122 Version : "1" ,
122123 ChainID : big .NewInt (1 ),
@@ -130,13 +131,13 @@ func TestTypedDataCase2(t *testing.T) {
130131 },
131132 }
132133
133- domainHash , err := typedData .hashStruct ("EIP712Domain" , typedData .Domain .Map ())
134+ domainHash , err := typedData .HashStruct ("EIP712Domain" , typedData .Domain .Map ())
134135 assert .NoError (t , err )
135- assert .Equal (t , "0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f" , HexEncode (domainHash ))
136+ assert .Equal (t , "0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f" , ethcoder . HexEncode (domainHash ))
136137
137138 digest , err := typedData .EncodeDigest ()
138139 assert .NoError (t , err )
139- assert .Equal (t , "0x2218fda59750be7bb9e5dfb2b49e4ec000dc2542862c5826f1fe980d6d727e95" , HexEncode (digest ))
140+ assert .Equal (t , "0x2218fda59750be7bb9e5dfb2b49e4ec000dc2542862c5826f1fe980d6d727e95" , ethcoder . HexEncode (digest ))
140141
141142 // fmt.Println("===> digest", HexEncode(digest))
142143
0 commit comments