types.NewSpendInput(nil, bc.NewHash([32]byte{0x01}), *consensus.BTMAssetID, 1, 1, []byte{0x51}),
},
Outputs: []*types.TxOutput{
- types.NewTxOutput(*consensus.BTMAssetID, 1, []byte{0x6a}),
+ types.NewIntraChainOutput(*consensus.BTMAssetID, 1, []byte{0x6a}),
},
}),
//tx1
types.NewSpendInput(nil, bc.NewHash([32]byte{0x01}), *consensus.BTMAssetID, 1, 1, []byte{0x51}),
},
Outputs: []*types.TxOutput{
- types.NewTxOutput(*consensus.BTMAssetID, 1, []byte{0x6b}),
+ types.NewIntraChainOutput(*consensus.BTMAssetID, 1, []byte{0x6b}),
},
}),
//tx2
types.NewSpendInput(nil, bc.NewHash([32]byte{0x02}), bc.NewAssetID([32]byte{0xa1}), 4, 1, []byte{0x51}),
},
Outputs: []*types.TxOutput{
- types.NewTxOutput(*consensus.BTMAssetID, 1, []byte{0x6b}),
- types.NewTxOutput(bc.NewAssetID([32]byte{0xa1}), 4, []byte{0x61}),
+ types.NewIntraChainOutput(*consensus.BTMAssetID, 1, []byte{0x6b}),
+ types.NewIntraChainOutput(bc.NewAssetID([32]byte{0xa1}), 4, []byte{0x61}),
},
}),
//tx3
types.NewTx(types.TxData{
+
SerializedSize: 100,
Inputs: []*types.TxInput{
- types.NewSpendInput(nil, testutil.MustDecodeHash("dbea684b5c5153ed7729669a53d6c59574f26015a3e1eb2a0e8a1c645425a764"), bc.NewAssetID([32]byte{0xa1}), 4, 1, []byte{0x61}),
+ types.NewSpendInput(nil, testutil.MustDecodeHash("7d3f8e8474775f9fab2a7370529f0569a2199b22a5a83d235a036f50de3e8c84"), bc.NewAssetID([32]byte{0xa1}), 4, 1, []byte{0x61}),
},
Outputs: []*types.TxOutput{
- types.NewTxOutput(bc.NewAssetID([32]byte{0xa1}), 3, []byte{0x62}),
- types.NewTxOutput(bc.NewAssetID([32]byte{0xa1}), 1, []byte{0x63}),
+ types.NewIntraChainOutput(bc.NewAssetID([32]byte{0xa1}), 3, []byte{0x62}),
+ types.NewIntraChainOutput(bc.NewAssetID([32]byte{0xa1}), 1, []byte{0x63}),
},
}),
//tx4
types.NewTx(types.TxData{
SerializedSize: 100,
Inputs: []*types.TxInput{
- types.NewSpendInput(nil, testutil.MustDecodeHash("d84d0be0fd08e7341f2d127749bb0d0844d4560f53bd54861cee9981fd922cad"), bc.NewAssetID([32]byte{0xa1}), 3, 0, []byte{0x62}),
+ types.NewSpendInput(nil, testutil.MustDecodeHash("9a26cde504a5d7190dbed119280276f9816d9c2b7d20c768b312be57930fe840"), bc.NewAssetID([32]byte{0xa1}), 3, 0, []byte{0x62}),
},
Outputs: []*types.TxOutput{
- types.NewTxOutput(bc.NewAssetID([32]byte{0xa1}), 2, []byte{0x64}),
- types.NewTxOutput(bc.NewAssetID([32]byte{0xa1}), 1, []byte{0x65}),
+ types.NewIntraChainOutput(bc.NewAssetID([32]byte{0xa1}), 2, []byte{0x64}),
+ types.NewIntraChainOutput(bc.NewAssetID([32]byte{0xa1}), 1, []byte{0x65}),
},
}),
//tx5
types.NewSpendInput(nil, bc.NewHash([32]byte{0x01}), *consensus.BTMAssetID, 1, 1, []byte{0x51}),
},
Outputs: []*types.TxOutput{
- types.NewTxOutput(*consensus.BTMAssetID, 0, []byte{0x51}),
+ types.NewIntraChainOutput(*consensus.BTMAssetID, 0, []byte{0x51}),
},
}),
//tx6
SerializedSize: 100,
Inputs: []*types.TxInput{
types.NewSpendInput(nil, bc.NewHash([32]byte{0x01}), *consensus.BTMAssetID, 3, 1, []byte{0x51}),
- types.NewSpendInput(nil, testutil.MustDecodeHash("d84d0be0fd08e7341f2d127749bb0d0844d4560f53bd54861cee9981fd922cad"), bc.NewAssetID([32]byte{0xa1}), 3, 0, []byte{0x62}),
+ types.NewSpendInput(nil, testutil.MustDecodeHash("9a26cde504a5d7190dbed119280276f9816d9c2b7d20c768b312be57930fe840"), bc.NewAssetID([32]byte{0xa1}), 3, 0, []byte{0x62}),
},
Outputs: []*types.TxOutput{
- types.NewTxOutput(*consensus.BTMAssetID, 2, []byte{0x51}),
- types.NewTxOutput(bc.NewAssetID([32]byte{0xa1}), 0, []byte{0x65}),
+ types.NewIntraChainOutput(*consensus.BTMAssetID, 2, []byte{0x51}),
+ types.NewIntraChainOutput(bc.NewAssetID([32]byte{0xa1}), 0, []byte{0x65}),
+ },
+ }),
+ //tx7
+ types.NewTx(types.TxData{
+ SerializedSize: 150,
+ TimeRange: 0,
+ Inputs: []*types.TxInput{
+ types.NewSpendInput(nil, bc.NewHash([32]byte{0x01}), *consensus.BTMAssetID, 1, 1, []byte{0x51}),
+ types.NewSpendInput(nil, bc.NewHash([32]byte{0x02}), bc.NewAssetID([32]byte{0xa1}), 4, 1, []byte{0x51}),
+ },
+ Outputs: []*types.TxOutput{
+ types.NewIntraChainOutput(*consensus.BTMAssetID, 1, []byte{0x6b}),
+ types.NewVoteOutput(bc.NewAssetID([32]byte{0xa1}), 4, []byte{0x61}, []byte("a8f410b9f7cd9ce352d215ed17c85559c351dc8d18ed89ad403ca28cfc423f612e04a1c9584f945c286c47ec1e5b8405c65ff56e31f44a2627aca4f77e03936f")),
},
}),
}
func (s *mockStore) BlockExist(hash *bc.Hash) bool { return false }
func (s *mockStore) GetBlock(*bc.Hash) (*types.Block, error) { return nil, nil }
+func (s *mockStore) GetBlockHeader(*bc.Hash) (*types.BlockHeader, error) { return nil, nil }
func (s *mockStore) GetStoreStatus() *BlockStoreState { return nil }
func (s *mockStore) GetTransactionStatus(*bc.Hash) (*bc.TransactionStatus, error) { return nil, nil }
func (s *mockStore) GetTransactionsUtxo(*state.UtxoViewpoint, []*bc.Tx) error { return nil }
func (s *mockStore) GetUtxo(*bc.Hash) (*storage.UtxoEntry, error) { return nil, nil }
-func (s *mockStore) LoadBlockIndex(uint64) (*state.BlockIndex, error) { return nil, nil }
+func (s *mockStore) GetConsensusResult(uint64) (*state.ConsensusResult, error) { return nil, nil }
+func (s *mockStore) GetMainChainHash(uint64) (*bc.Hash, error) { return nil, nil }
+func (s *mockStore) GetBlockHashesByHeight(uint64) ([]*bc.Hash, error) { return nil, nil }
func (s *mockStore) SaveBlock(*types.Block, *bc.TransactionStatus) error { return nil }
-func (s *mockStore) SaveChainStatus(*state.BlockNode, *state.UtxoViewpoint) error { return nil }
+func (s *mockStore) SaveBlockHeader(*types.BlockHeader) error { return nil }
+func (s *mockStore) SaveChainStatus(*types.BlockHeader, *types.BlockHeader, []*types.BlockHeader, *state.UtxoViewpoint, []*state.ConsensusResult) error {
+ return nil
+}
func TestAddOrphan(t *testing.T) {
cases := []struct {
StatusFail: true,
},
},
+ {
+ before: &TxPool{
+ pool: map[bc.Hash]*TxDesc{},
+ utxo: map[bc.Hash]*types.Tx{},
+ eventDispatcher: dispatcher,
+ },
+ after: &TxPool{
+ pool: map[bc.Hash]*TxDesc{
+ testTxs[7].ID: {
+ Tx: testTxs[7],
+ StatusFail: false,
+ },
+ },
+ utxo: map[bc.Hash]*types.Tx{
+ *testTxs[7].ResultIds[0]: testTxs[7],
+ *testTxs[7].ResultIds[1]: testTxs[7],
+ },
+ },
+ addTx: &TxDesc{
+ Tx: testTxs[7],
+ StatusFail: false,
+ },
+ },
+ {
+ before: &TxPool{
+ pool: map[bc.Hash]*TxDesc{},
+ utxo: map[bc.Hash]*types.Tx{},
+ eventDispatcher: dispatcher,
+ },
+ after: &TxPool{
+ pool: map[bc.Hash]*TxDesc{
+ testTxs[7].ID: {
+ Tx: testTxs[7],
+ StatusFail: true,
+ },
+ },
+ utxo: map[bc.Hash]*types.Tx{
+ *testTxs[7].ResultIds[0]: testTxs[7],
+ },
+ },
+ addTx: &TxDesc{
+ Tx: testTxs[7],
+ StatusFail: true,
+ },
+ },
}
for i, c := range cases {
},
}
- before.ExpireOrphan(time.Unix(1633479701, 0))
+ before.expireOrphan(time.Unix(1633479701, 0))
if !testutil.DeepEqual(before, want) {
t.Errorf("got %v want %v", before, want)
}
func (s *mockStore1) BlockExist(hash *bc.Hash) bool { return false }
func (s *mockStore1) GetBlock(*bc.Hash) (*types.Block, error) { return nil, nil }
+func (s *mockStore1) GetBlockHeader(*bc.Hash) (*types.BlockHeader, error) { return nil, nil }
func (s *mockStore1) GetStoreStatus() *BlockStoreState { return nil }
func (s *mockStore1) GetTransactionStatus(*bc.Hash) (*bc.TransactionStatus, error) { return nil, nil }
func (s *mockStore1) GetTransactionsUtxo(utxoView *state.UtxoViewpoint, tx []*bc.Tx) error {
+ // TODO:
for _, hash := range testTxs[2].SpentOutputIDs {
- utxoView.Entries[hash] = &storage.UtxoEntry{IsCoinBase: false, Spent: false}
+ utxoView.Entries[hash] = &storage.UtxoEntry{Type: storage.NormalUTXOType, Spent: false}
}
return nil
}
-func (s *mockStore1) GetUtxo(*bc.Hash) (*storage.UtxoEntry, error) { return nil, nil }
-func (s *mockStore1) LoadBlockIndex(uint64) (*state.BlockIndex, error) { return nil, nil }
-func (s *mockStore1) SaveBlock(*types.Block, *bc.TransactionStatus) error { return nil }
-func (s *mockStore1) SaveChainStatus(*state.BlockNode, *state.UtxoViewpoint) error { return nil }
+func (s *mockStore1) GetUtxo(*bc.Hash) (*storage.UtxoEntry, error) { return nil, nil }
+func (s *mockStore1) GetConsensusResult(uint64) (*state.ConsensusResult, error) { return nil, nil }
+func (s *mockStore1) GetMainChainHash(uint64) (*bc.Hash, error) { return nil, nil }
+func (s *mockStore1) GetBlockHashesByHeight(uint64) ([]*bc.Hash, error) { return nil, nil }
+func (s *mockStore1) SaveBlock(*types.Block, *bc.TransactionStatus) error { return nil }
+func (s *mockStore1) SaveBlockHeader(*types.BlockHeader) error { return nil }
+func (s *mockStore1) SaveChainStatus(*types.BlockHeader, *types.BlockHeader, []*types.BlockHeader, *state.UtxoViewpoint, []*state.ConsensusResult) error {
+ return nil
+}
func TestProcessTransaction(t *testing.T) {
txPool := &TxPool{
{
want: &TxPool{},
addTx: &TxDesc{
- Tx: testTxs[3],
- StatusFail: false,
- },
- },
- //Dust tx
- {
- want: &TxPool{},
- addTx: &TxDesc{
- Tx: testTxs[4],
- StatusFail: false,
- },
- },
- //Dust tx
- {
- want: &TxPool{},
- addTx: &TxDesc{
Tx: testTxs[5],
StatusFail: false,
},