|
|
@ -62,9 +62,13 @@ func TestBlockFromPendingTxs(t *testing.T) { |
|
|
|
node, err := NewNode(privK, bc, true) |
|
|
|
assert.Nil(t, err) |
|
|
|
|
|
|
|
addr0 := core.Address(core.HashBytes([]byte("addr0"))) |
|
|
|
addr1 := core.Address(core.HashBytes([]byte("addr1"))) |
|
|
|
tx := core.NewTx(addr0, addr1, []core.Input{}, []core.Output{}) |
|
|
|
privK0, err := core.NewKey() |
|
|
|
assert.Nil(t, err) |
|
|
|
pubK0 := privK0.PublicKey |
|
|
|
privK1, err := core.NewKey() |
|
|
|
assert.Nil(t, err) |
|
|
|
pubK1 := privK1.PublicKey |
|
|
|
tx := core.NewTx(&pubK0, &pubK1, []core.Input{}, []core.Output{}) |
|
|
|
node.AddToPendingTxs(*tx) |
|
|
|
block, err := node.BlockFromPendingTxs() |
|
|
|
assert.Nil(t, err) |
|
|
@ -87,10 +91,15 @@ func TestBlockFromPendingTxsIteration(t *testing.T) { |
|
|
|
node, err := NewNode(privK, bc, true) |
|
|
|
assert.Nil(t, err) |
|
|
|
|
|
|
|
addr0 := core.Address(core.HashBytes([]byte("addr0"))) |
|
|
|
addr1 := core.Address(core.HashBytes([]byte("addr1"))) |
|
|
|
privK0, err := core.NewKey() |
|
|
|
assert.Nil(t, err) |
|
|
|
pubK0 := privK0.PublicKey |
|
|
|
privK1, err := core.NewKey() |
|
|
|
assert.Nil(t, err) |
|
|
|
pubK1 := privK1.PublicKey |
|
|
|
|
|
|
|
for i := 0; i < 10; i++ { |
|
|
|
tx := core.NewTx(addr0, addr1, []core.Input{}, []core.Output{}) |
|
|
|
tx := core.NewTx(&pubK0, &pubK1, []core.Input{}, []core.Output{}) |
|
|
|
node.AddToPendingTxs(*tx) |
|
|
|
} |
|
|
|
block, err := node.BlockFromPendingTxs() |
|
|
@ -98,3 +107,35 @@ func TestBlockFromPendingTxsIteration(t *testing.T) { |
|
|
|
assert.True(t, core.CheckBlockPoW(block, node.Bc.Difficulty)) |
|
|
|
assert.True(t, node.Bc.VerifyBlock(block)) |
|
|
|
} |
|
|
|
|
|
|
|
func TestFromGenesisToTenBlocks(t *testing.T) { |
|
|
|
dir, err := ioutil.TempDir("", "db") |
|
|
|
assert.Nil(t, err) |
|
|
|
db, err := db.New(dir) |
|
|
|
assert.Nil(t, err) |
|
|
|
|
|
|
|
privK, err := core.NewKey() |
|
|
|
assert.Nil(t, err) |
|
|
|
|
|
|
|
dif := uint64(1) |
|
|
|
bc := core.NewBlockchain(db, dif) |
|
|
|
node, err := NewNode(privK, bc, true) |
|
|
|
assert.Nil(t, err) |
|
|
|
|
|
|
|
// create the genesis block
|
|
|
|
genesisBlock, err := node.CreateGenesis() |
|
|
|
assert.Nil(t, err) |
|
|
|
assert.NotEqual(t, genesisBlock.Signature, core.Signature{}) |
|
|
|
assert.NotEqual(t, genesisBlock.Hash, core.Hash{}) |
|
|
|
|
|
|
|
// add the genesis block into the blockchain
|
|
|
|
err = node.Bc.AddBlock(genesisBlock) |
|
|
|
assert.Nil(t, err) |
|
|
|
assert.NotEqual(t, genesisBlock.Hash, core.Hash{}) |
|
|
|
assert.Equal(t, genesisBlock.Hash, node.Bc.LastBlock.Hash) |
|
|
|
|
|
|
|
// TODO add another block
|
|
|
|
block := node.NewBlock([]core.Tx{}) |
|
|
|
err = node.Bc.AddBlock(block) |
|
|
|
assert.Nil(t, err) |
|
|
|
} |