OSDN Git Service

Merge pull request #201 from Bytom/v0.1
[bytom/vapor.git] / protocol / bc / types / merkle_test.go
index 2f22c55..2cc7bbe 100644 (file)
@@ -2,10 +2,8 @@ package types
 
 import (
        "encoding/hex"
-
        "math/rand"
        "testing"
-       "time"
 
        "github.com/vapor/protocol/bc"
        "github.com/vapor/protocol/vm"
@@ -23,7 +21,7 @@ func TestMerkleRoot(t *testing.T) {
                                []byte("00000"),
                        },
                },
-               want: testutil.MustDecodeHash("011a6b552cc8eced01c403b138c51f906d0ccd0bbdf986d2b3e0cc69a4291737"),
+               want: testutil.MustDecodeHash("fe34dbd5da0ce3656f423fd7aad7fc7e879353174d33a6446c2ed0e3f3512101"),
        }, {
                witnesses: [][][]byte{
                        {
@@ -35,7 +33,7 @@ func TestMerkleRoot(t *testing.T) {
                                []byte("111111"),
                        },
                },
-               want: testutil.MustDecodeHash("64cef8abecac041b87110309dd9068d4935a31fb1bd1572144d11ead9da91dba"),
+               want: testutil.MustDecodeHash("0e4b4c1af18b8f59997804d69f8f66879ad5e30027346ee003ff7c7a512e5554"),
        }, {
                witnesses: [][][]byte{
                        {
@@ -48,7 +46,7 @@ func TestMerkleRoot(t *testing.T) {
                                []byte("222222"),
                        },
                },
-               want: testutil.MustDecodeHash("64cef8abecac041b87110309dd9068d4935a31fb1bd1572144d11ead9da91dba"),
+               want: testutil.MustDecodeHash("0e4b4c1af18b8f59997804d69f8f66879ad5e30027346ee003ff7c7a512e5554"),
        }}
 
        for _, c := range cases {
@@ -83,14 +81,12 @@ func TestMerkleRoot(t *testing.T) {
 
 func TestDuplicateLeaves(t *testing.T) {
        trueProg := []byte{byte(vm.OP_TRUE)}
-       assetID := bc.ComputeAssetID(trueProg, 1, &bc.EmptyStringHash)
+       assetID := bc.AssetID{V0: 9999}
        txs := make([]*bc.Tx, 6)
        for i := uint64(0); i < 6; i++ {
-               now := []byte(time.Now().String())
                txs[i] = NewTx(TxData{
                        Version: 1,
-                       Inputs:  []*TxInput{NewIssuanceInput(now, i, trueProg, nil, nil)},
-                       Outputs: []*TxOutput{NewTxOutput(assetID, i, trueProg)},
+                       Outputs: []*TxOutput{NewIntraChainOutput(assetID, i, trueProg)},
                }).Tx
        }
 
@@ -115,14 +111,11 @@ func TestDuplicateLeaves(t *testing.T) {
 
 func TestAllDuplicateLeaves(t *testing.T) {
        trueProg := []byte{byte(vm.OP_TRUE)}
-       assetID := bc.ComputeAssetID(trueProg, 1, &bc.EmptyStringHash)
-       now := []byte(time.Now().String())
-       issuanceInp := NewIssuanceInput(now, 1, trueProg, nil, nil)
+       assetID := bc.AssetID{V0: 9999}
 
        tx := NewTx(TxData{
                Version: 1,
-               Inputs:  []*TxInput{issuanceInp},
-               Outputs: []*TxOutput{NewTxOutput(assetID, 1, trueProg)},
+               Outputs: []*TxOutput{NewIntraChainOutput(assetID, 1, trueProg)},
        }).Tx
        tx1, tx2, tx3, tx4, tx5, tx6 := tx, tx, tx, tx, tx, tx
 
@@ -428,14 +421,12 @@ func mockTransactions(txCount int) ([]*Tx, []*bc.Tx) {
        var txs []*Tx
        var bcTxs []*bc.Tx
        trueProg := []byte{byte(vm.OP_TRUE)}
-       assetID := bc.ComputeAssetID(trueProg, 1, &bc.EmptyStringHash)
-       for i := 0; i < txCount; i++ {
-               now := []byte(time.Now().String())
-               issuanceInp := NewIssuanceInput(now, 1, trueProg, nil, nil)
+       assetID := bc.AssetID{V0: 9999}
+       for i := uint64(0); i < uint64(txCount); i++ {
                tx := NewTx(TxData{
                        Version: 1,
-                       Inputs:  []*TxInput{issuanceInp},
-                       Outputs: []*TxOutput{NewTxOutput(assetID, 1, trueProg)},
+                       Inputs:  []*TxInput{NewSpendInput(nil, bc.Hash{V0: i + 1}, assetID, i, i, trueProg)},
+                       Outputs: []*TxOutput{NewIntraChainOutput(assetID, 1, trueProg)},
                })
                txs = append(txs, tx)
                bcTxs = append(bcTxs, tx.Tx)