|
|
@ -143,6 +143,75 @@ func TestGenesisSaveLoad(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* TODO: Write better tests, and also refactor out common code |
|
|
|
func TestSendTxStateSave(t *testing.T) { |
|
|
|
|
|
|
|
// Generate a state, save & load it.
|
|
|
|
s0, privAccounts, _ := RandGenesisState(10, true, 1000, 5, true, 1000) |
|
|
|
|
|
|
|
sendTx := &SendTx{ |
|
|
|
Inputs: []*TxInput{ |
|
|
|
&TxInput{ |
|
|
|
Address: privAccounts[0].PubKey.Address(), |
|
|
|
Amount: 100, |
|
|
|
Sequence: 1, |
|
|
|
Signature: nil, |
|
|
|
PubKey: privAccounts[0].PubKey, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Outputs: []*TxOutput{ |
|
|
|
&TxOutput{ |
|
|
|
Address: []byte("01234567890123456789"), |
|
|
|
Amount: 100, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
sendTx.Inputs[0].Signature = privAccounts[0].Sign(sendTx) |
|
|
|
|
|
|
|
// Mutate the state to append block with sendTx
|
|
|
|
block := &Block{ |
|
|
|
Header: &Header{ |
|
|
|
Network: config.App.GetString("Network"), |
|
|
|
Height: 1, |
|
|
|
Time: s0.LastBlockTime.Add(time.Minute), |
|
|
|
Fees: 0, |
|
|
|
NumTxs: 1, |
|
|
|
LastBlockHash: s0.LastBlockHash, |
|
|
|
LastBlockParts: s0.LastBlockParts, |
|
|
|
StateHash: nil, |
|
|
|
}, |
|
|
|
Validation: &Validation{}, |
|
|
|
Data: &Data{ |
|
|
|
Txs: []Tx{sendTx}, |
|
|
|
}, |
|
|
|
} |
|
|
|
blockParts := NewPartSetFromData(BinaryBytes(block)) |
|
|
|
|
|
|
|
// The last argument to AppendBlock() is `false`,
|
|
|
|
// which sets Block.Header.StateHash.
|
|
|
|
err := s0.Copy().AppendBlock(block, blockParts.Header(), false) |
|
|
|
if err != nil { |
|
|
|
t.Error("Error appending initial block:", err) |
|
|
|
} |
|
|
|
if len(block.Header.StateHash) == 0 { |
|
|
|
t.Error("Expected StateHash but got nothing.") |
|
|
|
} |
|
|
|
|
|
|
|
// Now append the block to s0.
|
|
|
|
// This time we also check the StateHash (as computed above).
|
|
|
|
err = s0.AppendBlock(block, blockParts.Header(), true) |
|
|
|
if err != nil { |
|
|
|
t.Error("Error appending initial block:", err) |
|
|
|
} |
|
|
|
|
|
|
|
// Save s0
|
|
|
|
s0.Save() |
|
|
|
fmt.Printf("s0.accounts.Hash(): %X\n", s0.accounts.Hash()) |
|
|
|
s0.DB.Print() |
|
|
|
|
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
func TestTxSequence(t *testing.T) { |
|
|
|
|
|
|
|
state, privAccounts, _ := RandGenesisState(3, true, 1000, 1, true, 1000) |
|
|
|