added create from account for each test

This commit is contained in:
Dustin Brickwood 2018-08-01 15:58:14 -04:00
parent 112c47bf29
commit c121072d0f

View file

@ -45,11 +45,11 @@ func TestBlock(t *testing.T) {
signer := types.NewEIP155Signer(big.NewInt(2147483647)) signer := types.NewEIP155Signer(big.NewInt(2147483647))
//Nonce, To Address,Value, GasLimit, Gasprice, data //Nonce, To Address,Value, GasLimit, Gasprice, data
tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11}) tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(5), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11})
mytx, _ := types.SignTx(tx1, signer, key) mytx, _ := types.SignTx(tx1, signer, key)
tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(222), 2222, big.NewInt(22222), []byte{0x22, 0x22, 0x22}) tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(5), 2222, big.NewInt(22222), []byte{0x22, 0x22, 0x22})
mytx2, _ := types.SignTx(tx2, signer, key) mytx2, _ := types.SignTx(tx2, signer, key)
tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33}) tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(5), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33})
mytx3, _ := types.SignTx(tx3, signer, key) mytx3, _ := types.SignTx(tx3, signer, key)
txs := []*types.Transaction{mytx, mytx2, mytx3} txs := []*types.Transaction{mytx, mytx2, mytx3}
@ -67,15 +67,18 @@ func TestBlock(t *testing.T) {
receipts := []*types.Receipt{receipt} receipts := []*types.Receipt{receipt}
block := types.NewBlock(&types.Header{Number: big.NewInt(315)}, txs, nil, receipts) block := types.NewBlock(&types.Header{Number: big.NewInt(315)}, txs, nil, receipts)
// Write and verify the block in the database
if err := core.SWriteBlock(block, receipts); err != nil {
t.Fatalf("Failed to write block into database: %v", err)
}
sqldb, err := core.DBConnection() sqldb, err := core.DBConnection()
if err != nil { if err != nil {
panic(err) panic(err)
} }
fromAddr := "0x71562b71999873db5b286df957af199ec94617f7"
core.CreateAccount(sqldb, fromAddr, "50", "1")
// Write and verify the block in the database
if err := core.SWriteBlock(block, receipts); err != nil {
t.Fatalf("Failed to write block into database: %v", err)
}
entry := core.SGetBlock(sqldb, block.Number().String()) entry := core.SGetBlock(sqldb, block.Number().String())
byt := []byte(entry) byt := []byte(entry)
@ -132,11 +135,11 @@ func TestBlock(t *testing.T) {
signer := types.NewEIP155Signer(big.NewInt(2147483647)) signer := types.NewEIP155Signer(big.NewInt(2147483647))
//Nonce, To Address,Value, GasLimit, Gasprice, data //Nonce, To Address,Value, GasLimit, Gasprice, data
tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11}) tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(5), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11})
mytx, _ := types.SignTx(tx1, signer, key) mytx, _ := types.SignTx(tx1, signer, key)
tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(222), 2222, big.NewInt(22222), []byte{0x22, 0x22, 0x22}) tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(5), 2222, big.NewInt(22222), []byte{0x22, 0x22, 0x22})
mytx2, _ := types.SignTx(tx2, signer, key) mytx2, _ := types.SignTx(tx2, signer, key)
tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33}) tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(5), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33})
mytx3, _ := types.SignTx(tx3, signer, key) mytx3, _ := types.SignTx(tx3, signer, key)
txs := []*types.Transaction{mytx, mytx2} txs := []*types.Transaction{mytx, mytx2}
txs1 := []*types.Transaction{mytx3} txs1 := []*types.Transaction{mytx3}
@ -158,6 +161,14 @@ func TestBlock(t *testing.T) {
block2 := types.NewBlock(&types.Header{Number: big.NewInt(320)}, txs1, nil, receipts) block2 := types.NewBlock(&types.Header{Number: big.NewInt(320)}, txs1, nil, receipts)
blocks := []*types.Block{block, block2} blocks := []*types.Block{block, block2}
sqldb, err := core.DBConnection()
if err != nil {
panic(err)
}
fromAddr := "0x71562b71999873db5b286df957af199ec94617f7"
core.CreateAccount(sqldb, fromAddr, "50", "1")
for _, bc := range blocks { for _, bc := range blocks {
// Write and verify the block in the database // Write and verify the block in the database
if err := core.SWriteBlock(bc, receipts); err != nil { if err := core.SWriteBlock(bc, receipts); err != nil {
@ -165,11 +176,6 @@ func TestBlock(t *testing.T) {
} }
} }
sqldb, err := core.DBConnection()
if err != nil {
panic(err)
}
response := core.SGetRecentBlock(sqldb) response := core.SGetRecentBlock(sqldb)
byteRes := []byte(response) byteRes := []byte(response)
var recentBlock core.SBlock var recentBlock core.SBlock
@ -320,11 +326,11 @@ func TestBlock(t *testing.T) {
signer := types.NewEIP155Signer(big.NewInt(2147483647)) signer := types.NewEIP155Signer(big.NewInt(2147483647))
//Nonce, To Address,Value, GasLimit, Gasprice, data //Nonce, To Address,Value, GasLimit, Gasprice, data
tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11}) tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(5), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11})
mytx, _ := types.SignTx(tx1, signer, key) mytx, _ := types.SignTx(tx1, signer, key)
tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(222), 2222, big.NewInt(22222), []byte{0x22, 0x22, 0x22}) tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(5), 2222, big.NewInt(22222), []byte{0x22, 0x22, 0x22})
mytx2, _ := types.SignTx(tx2, signer, key) mytx2, _ := types.SignTx(tx2, signer, key)
tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33}) tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(5), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33})
mytx3, _ := types.SignTx(tx3, signer, key) mytx3, _ := types.SignTx(tx3, signer, key)
txs := []*types.Transaction{mytx, mytx2, mytx3} txs := []*types.Transaction{mytx, mytx2, mytx3}
@ -343,14 +349,18 @@ func TestBlock(t *testing.T) {
receipts := []*types.Receipt{receipt1} receipts := []*types.Receipt{receipt1}
block := types.NewBlock(&types.Header{Number: big.NewInt(314)}, txs, nil, receipts) block := types.NewBlock(&types.Header{Number: big.NewInt(314)}, txs, nil, receipts)
if err := core.SWriteBlock(block, receipts); err != nil {
t.Fatalf("Failed to write block into database: %v", err)
}
sqldb, err := core.DBConnection() sqldb, err := core.DBConnection()
if err != nil { if err != nil {
panic(err) panic(err)
} }
fromAddr := "0x71562b71999873db5b286df957af199ec94617f7"
core.CreateAccount(sqldb, fromAddr, "50", "1")
if err := core.SWriteBlock(block, receipts); err != nil {
t.Fatalf("Failed to write block into database: %v", err)
}
for _, tx := range txs { for _, tx := range txs {
txn := core.SGetTransaction(sqldb, tx.Hash().String()) txn := core.SGetTransaction(sqldb, tx.Hash().String())
byt := []byte(txn) byt := []byte(txn)
@ -417,7 +427,7 @@ func TestBlock(t *testing.T) {
} }
core.ClearTables() core.ClearTables()
}) })
//
t.Run("TestAccountsToReturnAccounts", func(t *testing.T) { t.Run("TestAccountsToReturnAccounts", func(t *testing.T) {
key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
signer := types.NewEIP155Signer(big.NewInt(2147483647)) signer := types.NewEIP155Signer(big.NewInt(2147483647))
@ -492,7 +502,6 @@ func TestBlock(t *testing.T) {
if fromAddrEndNonce != accountDataFrom.AccountNonce { if fromAddrEndNonce != accountDataFrom.AccountNonce {
t.Fatalf("To account nonce [%v]: To account nonce not found", accountDataFrom.AccountNonce) t.Fatalf("To account nonce [%v]: To account nonce not found", accountDataFrom.AccountNonce)
} }
if getAllAccountTxs := core.SGetAccountTxs(sqldb, toAddr.String()); len(getAllAccountTxs) == 0 { if getAllAccountTxs := core.SGetAccountTxs(sqldb, toAddr.String()); len(getAllAccountTxs) == 0 {
t.Fatalf("GetAccountTxs [%v]: GetAccountTxs did not return correctly", getAllAccountTxs) t.Fatalf("GetAccountTxs [%v]: GetAccountTxs did not return correctly", getAllAccountTxs)
} }