forked from anchorageoss/tezosprotocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrevelation_test.go
41 lines (37 loc) · 1.62 KB
/
revelation_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
package tezosprotocol_test
import (
"encoding/hex"
"math/big"
"testing"
"github.com/anchorageoss/tezosprotocol/v3"
"github.com/stretchr/testify/require"
)
func TestEncodeRevelation(t *testing.T) {
require := require.New(t)
revelation := &tezosprotocol.Revelation{
Source: tezosprotocol.ContractID("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"),
Fee: big.NewInt(1257),
Counter: big.NewInt(1),
GasLimit: big.NewInt(10000),
StorageLimit: big.NewInt(0),
PublicKey: tezosprotocol.PublicKey("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"),
}
encodedBytes, err := revelation.MarshalBinary()
require.NoError(err)
encoded := hex.EncodeToString(encodedBytes)
expected := "6b0002298c03ed7d454a101eb7022bc95f7e5f41ac78e90901904e00004798d2cc98473d7e250c898885718afd2e4efbcb1a1595ab9730761ed830de0f"
require.Equal(expected, encoded)
}
func TestDecodeRevelation(t *testing.T) {
require := require.New(t)
encoded, err := hex.DecodeString("6b0002298c03ed7d454a101eb7022bc95f7e5f41ac78e90901904e00004798d2cc98473d7e250c898885718afd2e4efbcb1a1595ab9730761ed830de0f")
require.NoError(err)
revelation := tezosprotocol.Revelation{}
require.NoError(revelation.UnmarshalBinary(encoded))
require.Equal(tezosprotocol.ContractID("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"), revelation.Source)
require.Equal("1257", revelation.Fee.String())
require.Equal("1", revelation.Counter.String())
require.Equal("10000", revelation.GasLimit.String())
require.Equal("0", revelation.StorageLimit.String())
require.Equal(tezosprotocol.PublicKey("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"), revelation.PublicKey)
}