OSDN Git Service

Hulk did something
[bytom/vapor.git] / blockchain / txbuilder / witness_test.go
1 package txbuilder
2
3 import (
4         "encoding/json"
5         "testing"
6
7         "github.com/davecgh/go-spew/spew"
8
9         chainjson "github.com/vapor/encoding/json"
10         "github.com/vapor/testutil"
11 )
12
13 func TestWitnessJSON(t *testing.T) {
14         si := &SigningInstruction{
15                 Position: 17,
16                 WitnessComponents: []witnessComponent{
17                         DataWitness{1, 2, 3},
18                         &SignatureWitness{
19                                 Quorum: 4,
20                                 Keys: []keyID{{
21                                         XPub:           testutil.TestXPub,
22                                         DerivationPath: []chainjson.HexBytes{{5, 6, 7}},
23                                 }},
24                                 Sigs: []chainjson.HexBytes{{8, 9, 10}},
25                         },
26                         &RawTxSigWitness{
27                                 Quorum: 20,
28                                 Keys: []keyID{{
29                                         XPub:           testutil.TestXPub,
30                                         DerivationPath: []chainjson.HexBytes{{21, 22}},
31                                 }},
32                                 Sigs: []chainjson.HexBytes{{23, 24, 25}},
33                         },
34                 },
35         }
36
37         b, err := json.MarshalIndent(si, "", "  ")
38         if err != nil {
39                 t.Fatal(err)
40         }
41
42         var got SigningInstruction
43         err = json.Unmarshal(b, &got)
44         if err != nil {
45                 t.Fatalf("error on input %s: %s", b, err)
46         }
47
48         if !testutil.DeepEqual(si, &got) {
49                 t.Errorf("got:\n%s\nwant:\n%s\nJSON was: %s", spew.Sdump(&got), spew.Sdump(si), string(b))
50         }
51 }