X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=protocol%2Fstate%2Futxo_view_test.go;fp=protocol%2Fstate%2Futxo_view_test.go;h=e2697fabde2021e6f9c8aa7682dd31e08e869c8b;hp=8668a1c744d8cb999e3cc58073470b8f035a3a85;hb=54373c1a3efe0e373ec1605840a4363e4b246c46;hpb=ee01d543fdfe1fd0a4d548965c66f7923ea7b062 diff --git a/protocol/state/utxo_view_test.go b/protocol/state/utxo_view_test.go index 8668a1c7..e2697fab 100644 --- a/protocol/state/utxo_view_test.go +++ b/protocol/state/utxo_view_test.go @@ -10,7 +10,17 @@ import ( ) var defaultEntry = map[bc.Hash]bc.Entry{ - bc.Hash{V0: 0}: &bc.Output{ + bc.Hash{V0: 0}: &bc.IntraChainOutput{ + Source: &bc.ValueSource{ + Value: &bc.AssetAmount{ + AssetId: &bc.AssetID{V0: 0}, + }, + }, + }, +} + +var voteEntry = map[bc.Hash]bc.Entry{ + bc.Hash{V0: 0}: &bc.VoteOutput{ Source: &bc.ValueSource{ Value: &bc.AssetAmount{ AssetId: &bc.AssetID{V0: 0}, @@ -20,14 +30,14 @@ var defaultEntry = map[bc.Hash]bc.Entry{ } var gasOnlyTxEntry = map[bc.Hash]bc.Entry{ - bc.Hash{V1: 0}: &bc.Output{ + bc.Hash{V1: 0}: &bc.IntraChainOutput{ Source: &bc.ValueSource{ Value: &bc.AssetAmount{ AssetId: consensus.BTMAssetID, }, }, }, - bc.Hash{V1: 1}: &bc.Output{ + bc.Hash{V1: 1}: &bc.IntraChainOutput{ Source: &bc.ValueSource{ Value: &bc.AssetAmount{ AssetId: &bc.AssetID{V0: 999}, @@ -61,7 +71,7 @@ func TestApplyBlock(t *testing.T) { }, inputView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 0, false), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false), }, }, fetchView: NewUtxoViewpoint(), @@ -101,7 +111,7 @@ func TestApplyBlock(t *testing.T) { }, inputView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 0, true), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true), }, }, err: true, @@ -125,12 +135,12 @@ func TestApplyBlock(t *testing.T) { }, inputView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 0, false), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false), }, }, fetchView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 0, true), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true), }, }, err: false, @@ -155,12 +165,12 @@ func TestApplyBlock(t *testing.T) { }, inputView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(true, 0, false), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.CoinbaseUTXOType, 0, false), }, }, fetchView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(true, 0, true), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.CoinbaseUTXOType, 0, true), }, }, err: false, @@ -185,12 +195,12 @@ func TestApplyBlock(t *testing.T) { }, inputView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(true, 0, false), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.CoinbaseUTXOType, 0, false), }, }, fetchView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(true, 0, true), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.CoinbaseUTXOType, 0, true), }, }, err: true, @@ -216,7 +226,7 @@ func TestApplyBlock(t *testing.T) { inputView: NewUtxoViewpoint(), fetchView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(true, 0, false), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.CoinbaseUTXOType, 0, false), }, }, err: false, @@ -242,14 +252,14 @@ func TestApplyBlock(t *testing.T) { }, inputView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V1: 0}: storage.NewUtxoEntry(false, 0, false), - bc.Hash{V1: 1}: storage.NewUtxoEntry(false, 0, false), + bc.Hash{V1: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false), + bc.Hash{V1: 1}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false), }, }, fetchView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V1: 0}: storage.NewUtxoEntry(false, 0, true), - bc.Hash{V1: 1}: storage.NewUtxoEntry(false, 0, false), + bc.Hash{V1: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true), + bc.Hash{V1: 1}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false), }, }, gasOnlyTx: true, @@ -277,12 +287,71 @@ func TestApplyBlock(t *testing.T) { inputView: NewUtxoViewpoint(), fetchView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V1: 0}: storage.NewUtxoEntry(true, 0, false), + bc.Hash{V1: 0}: storage.NewUtxoEntry(storage.CoinbaseUTXOType, 0, false), }, }, gasOnlyTx: true, err: false, }, + { + block: &bc.Block{ + BlockHeader: &bc.BlockHeader{ + TransactionStatus: bc.NewTransactionStatus(), + }, + Transactions: []*bc.Tx{ + &bc.Tx{ + TxHeader: &bc.TxHeader{ + ResultIds: []*bc.Hash{}, + }, + SpentOutputIDs: []bc.Hash{ + bc.Hash{V0: 0}, + }, + Entries: voteEntry, + }, + }, + }, + inputView: &UtxoViewpoint{ + Entries: map[bc.Hash]*storage.UtxoEntry{ + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.VoteUTXOType, 0, false), + }, + }, + fetchView: &UtxoViewpoint{ + Entries: map[bc.Hash]*storage.UtxoEntry{ + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.VoteUTXOType, 0, true), + }, + }, + err: true, + }, + { + block: &bc.Block{ + BlockHeader: &bc.BlockHeader{ + Height: 10001, + TransactionStatus: bc.NewTransactionStatus(), + }, + Transactions: []*bc.Tx{ + &bc.Tx{ + TxHeader: &bc.TxHeader{ + ResultIds: []*bc.Hash{}, + }, + SpentOutputIDs: []bc.Hash{ + bc.Hash{V0: 0}, + }, + Entries: voteEntry, + }, + }, + }, + inputView: &UtxoViewpoint{ + Entries: map[bc.Hash]*storage.UtxoEntry{ + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.VoteUTXOType, 1, false), + }, + }, + fetchView: &UtxoViewpoint{ + Entries: map[bc.Hash]*storage.UtxoEntry{ + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.VoteUTXOType, 1, true), + }, + }, + err: false, + }, } for i, c := range cases { @@ -327,7 +396,7 @@ func TestDetachBlock(t *testing.T) { inputView: NewUtxoViewpoint(), fetchView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 0, false), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false), }, }, err: false, @@ -352,7 +421,7 @@ func TestDetachBlock(t *testing.T) { inputView: NewUtxoViewpoint(), fetchView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 0, true), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true), }, }, err: false, @@ -376,7 +445,7 @@ func TestDetachBlock(t *testing.T) { }, inputView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 0, false), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false), }, }, err: true, @@ -400,12 +469,12 @@ func TestDetachBlock(t *testing.T) { }, inputView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 0, true), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true), }, }, fetchView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 0, false), + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false), }, }, err: false, @@ -430,14 +499,14 @@ func TestDetachBlock(t *testing.T) { }, inputView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V1: 0}: storage.NewUtxoEntry(false, 0, true), - bc.Hash{V1: 1}: storage.NewUtxoEntry(false, 0, true), + bc.Hash{V1: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true), + bc.Hash{V1: 1}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true), }, }, fetchView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V1: 0}: storage.NewUtxoEntry(false, 0, false), - bc.Hash{V1: 1}: storage.NewUtxoEntry(false, 0, true), + bc.Hash{V1: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false), + bc.Hash{V1: 1}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true), }, }, gasOnlyTx: true, @@ -464,12 +533,37 @@ func TestDetachBlock(t *testing.T) { inputView: NewUtxoViewpoint(), fetchView: &UtxoViewpoint{ Entries: map[bc.Hash]*storage.UtxoEntry{ - bc.Hash{V1: 0}: storage.NewUtxoEntry(false, 0, true), + bc.Hash{V1: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true), }, }, gasOnlyTx: true, err: false, }, + { + block: &bc.Block{ + BlockHeader: &bc.BlockHeader{ + TransactionStatus: bc.NewTransactionStatus(), + }, + Transactions: []*bc.Tx{ + &bc.Tx{ + TxHeader: &bc.TxHeader{ + ResultIds: []*bc.Hash{}, + }, + SpentOutputIDs: []bc.Hash{ + bc.Hash{V0: 0}, + }, + Entries: voteEntry, + }, + }, + }, + inputView: NewUtxoViewpoint(), + fetchView: &UtxoViewpoint{ + Entries: map[bc.Hash]*storage.UtxoEntry{ + bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.VoteUTXOType, 0, false), + }, + }, + err: false, + }, } for i, c := range cases {