github.com/bytom/bytom@v1.1.2-0.20221014091027-bbcba3df6075/blockchain/txbuilder/witness_test.go (about)

     1  package txbuilder
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/davecgh/go-spew/spew"
     8  
     9  	chainjson "github.com/bytom/bytom/encoding/json"
    10  	"github.com/bytom/bytom/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  }