refactored unit tests to include set up and tear down

This commit is contained in:
Dustin Brickwood 2018-08-02 14:47:11 -04:00
parent 494e62c69a
commit 2abd54c29e
4 changed files with 164 additions and 292 deletions

View file

@ -271,6 +271,10 @@ func swriteFromBalance(sqldb *sql.DB, tx *types.Transaction) error {
func adjustBalanceFromAddr(sqldb *sql.DB, s SendAndReceive, value *big.Int) {
fromAddressBalance, fromAccountNonce, err := AccountExists(sqldb, s.From)
switch {
case err == sql.ErrNoRows:
fmt.Println("wtf", s.From)
}
if err != nil {
log.Fatal(err)
}
@ -288,7 +292,6 @@ func adjustBalanceFromAddr(sqldb *sql.DB, s SendAndReceive, value *big.Int) {
newAccountNonceSender.Add(fromNonce, nonceIncrement)
UpdateAccount(sqldb, s.From, newBalanceSender.String(), newAccountNonceSender.String())
//}
}
func balanceHelper(sqldb *sql.DB, s SendAndReceive, value *big.Int) {

View file

@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS blocks (
);
CREATE TABLE IF NOT EXISTS txs (
txHash text,
txHash text primary key unique,
to_addr text,
from_addr text,
blockhash text references blocks(hash),
@ -36,5 +36,19 @@ CREATE TABLE IF NOT EXISTS txs (
CREATE TABLE IF NOT EXISTS accounts (
addr text primary key unique,
balance numeric,
accountnonce numeric
);
accountNonce numeric
);
CREATE TABLE IF NOT EXISTS internalTxs (
id SERIAL PRIMARY KEY,
txHash text references txs(txHash),
type text,
to_addr text,
from_addr text,
amount text,
gas numeric,
gasUsed numeric,
time text,
input text,
output text
)

View file

@ -1,3 +1,4 @@
DROP TABLE internalTxs;
DROP TABLE txs;
DROP TABLE blocks;
DROP TABLE accounts;

View file

@ -22,6 +22,7 @@ const (
)
func TestBlock(t *testing.T) {
//SET UP FOR TEST FUNCTIONS
eth.NewShyftTestLDB()
core.InitDBTest()
shyftTracer := new(eth.ShyftTracer)
@ -40,135 +41,54 @@ func TestBlock(t *testing.T) {
eth.InitTracerEnv()
core.ClearTables()
key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
signer := types.NewEIP155Signer(big.NewInt(2147483647))
//Nonce, To Address,Value, GasLimit, Gasprice, data
tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(5), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11})
mytx1, _ := types.SignTx(tx1, signer, key)
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)
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)
txs := []*types.Transaction{mytx1, mytx2}
txs1 := []*types.Transaction{mytx3}
//Nonce,Value, GasLimit, Gasprice, data
contractCreation := types.NewContractCreation(1, big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11})
mytx4, _ := types.SignTx(contractCreation, signer, key)
txs2 := []*types.Transaction{mytx4}
receipt := &types.Receipt{
Status: types.ReceiptStatusSuccessful,
CumulativeGasUsed: 1,
Logs: []*types.Log{
{Address: common.BytesToAddress([]byte{0x11})},
{Address: common.BytesToAddress([]byte{0x01, 0x11})},
},
TxHash: common.BytesToHash([]byte{0x11, 0x11}),
ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}),
GasUsed: 111111,
}
receipts := []*types.Receipt{receipt}
block1 := types.NewBlock(&types.Header{Number: big.NewInt(323)}, txs, nil, receipts)
block2 := types.NewBlock(&types.Header{Number: big.NewInt(320)}, txs1, nil, receipts)
block3 := types.NewBlock(&types.Header{Number: big.NewInt(322)}, txs2, nil, receipts)
blocks := []*types.Block{block1, block2, block3}
sqldb, err := core.DBConnection()
if err != nil {
panic(err)
}
fromAddr := "0x71562b71999873db5b286df957af199ec94617f7"
fromAddrEndBalance := "75"
fromAddrEndNonce := "5"
toAddr := common.BytesToAddress([]byte{0x11})
core.CreateAccount(sqldb, fromAddr, "201", "1")
t.Run("TestBlockToReturnBlock", func(t *testing.T) {
key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
signer := types.NewEIP155Signer(big.NewInt(2147483647))
//Nonce, To Address,Value, GasLimit, Gasprice, data
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)
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)
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)
txs := []*types.Transaction{mytx, mytx2, mytx3}
receipt := &types.Receipt{
Status: types.ReceiptStatusSuccessful,
CumulativeGasUsed: 1,
Logs: []*types.Log{
{Address: common.BytesToAddress([]byte{0x11})},
{Address: common.BytesToAddress([]byte{0x01, 0x11})},
},
TxHash: common.BytesToHash([]byte{0x11, 0x11}),
ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}),
GasUsed: 111111,
}
receipts := []*types.Receipt{receipt}
block := types.NewBlock(&types.Header{Number: big.NewInt(315)}, txs, nil, receipts)
sqldb, err := core.DBConnection()
if err != nil {
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())
byt := []byte(entry)
var data core.SBlock
json.Unmarshal(byt, &data)
//TODO Difficulty, rewards, age
if block.Hash().String() != data.Hash {
t.Fatalf("Block Hash [%v]: Block hash not found", block.Hash().String())
}
if block.Coinbase().String() != data.Coinbase {
t.Fatalf("Block coinbase [%v]: Block coinbase not found", block.Coinbase().String())
}
if block.Number().String() != data.Number {
t.Fatalf("Block number [%v]: Block number not found", block.Number().String())
}
if block.GasUsed() != data.GasUsed {
t.Fatalf("Gas Used [%v]: Gas used not found", block.GasUsed())
}
if block.GasLimit() != data.GasLimit {
t.Fatalf("Gas Limit [%v]: Gas limit not found", block.GasLimit())
}
if block.Transactions().Len() != data.TxCount {
t.Fatalf("Tx Count [%v]: Tx Count not found", block.Transactions().Len())
}
if len(block.Uncles()) != data.UncleCount {
t.Fatalf("Uncle count [%v]: Uncle count not found", len(block.Uncles()))
}
if block.ParentHash().String() != data.ParentHash {
t.Fatalf("Parent hash [%v]: Parent hash not found", block.ParentHash().String())
}
if block.UncleHash().String() != data.UncleHash {
t.Fatalf("Uncle hash [%v]: Uncle hash not found", block.UncleHash().String())
}
if block.Size().String() != data.Size {
t.Fatalf("Size [%v]: Size not found", block.Size().String())
}
if block.Nonce() != data.Nonce {
t.Fatalf("Block nonce [%v]: Block nonce not found", block.Nonce())
}
if getAllBlocks := core.SGetAllBlocks(sqldb); len(getAllBlocks) == 0 {
t.Fatalf("GetAllBlocks [%v]: GetAllBlocks did not return correctly", getAllBlocks)
}
if getAllBlocksMinedByAddress := core.SGetAllBlocksMinedByAddress(sqldb, block.Coinbase().String()); len(getAllBlocksMinedByAddress) == 0 {
t.Fatalf("GetAllBlocksMinedByAddress [%v]: GetAllBlocksMinedByAddress did not return correctly", getAllBlocksMinedByAddress)
}
core.ClearTables()
})
t.Run("TestGetRecentBlock", func(t *testing.T) {
key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
signer := types.NewEIP155Signer(big.NewInt(2147483647))
//Nonce, To Address,Value, GasLimit, Gasprice, data
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)
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)
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)
txs := []*types.Transaction{mytx, mytx2}
txs1 := []*types.Transaction{mytx3}
receipt1 := &types.Receipt{
Status: types.ReceiptStatusSuccessful,
CumulativeGasUsed: 1,
Logs: []*types.Log{
{Address: common.BytesToAddress([]byte{0x11})},
{Address: common.BytesToAddress([]byte{0x01, 0x11})},
},
TxHash: common.BytesToHash([]byte{0x11, 0x11}),
ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}),
GasUsed: 111111,
}
receipts := []*types.Receipt{receipt1}
block := types.NewBlock(&types.Header{Number: big.NewInt(322)}, txs, nil, receipts)
block2 := types.NewBlock(&types.Header{Number: big.NewInt(320)}, txs1, nil, receipts)
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 {
// Write and verify the block in the database
if err := core.SWriteBlock(bc, receipts); err != nil {
@ -176,90 +96,107 @@ func TestBlock(t *testing.T) {
}
}
entry := core.SGetBlock(sqldb, block1.Number().String())
byt := []byte(entry)
var data core.SBlock
json.Unmarshal(byt, &data)
//TODO Difficulty, rewards, age
if block1.Hash().String() != data.Hash {
t.Fatalf("Block Hash [%v]: Block hash not found", block1.Hash().String())
}
if block1.Coinbase().String() != data.Coinbase {
t.Fatalf("Block coinbase [%v]: Block coinbase not found", block1.Coinbase().String())
}
if block1.Number().String() != data.Number {
t.Fatalf("Block number [%v]: Block number not found", block1.Number().String())
}
if block1.GasUsed() != data.GasUsed {
t.Fatalf("Gas Used [%v]: Gas used not found", block1.GasUsed())
}
if block1.GasLimit() != data.GasLimit {
t.Fatalf("Gas Limit [%v]: Gas limit not found", block1.GasLimit())
}
if block1.Transactions().Len() != data.TxCount {
t.Fatalf("Tx Count [%v]: Tx Count not found", block1.Transactions().Len())
}
if len(block1.Uncles()) != data.UncleCount {
t.Fatalf("Uncle count [%v]: Uncle count not found", len(block1.Uncles()))
}
if block1.ParentHash().String() != data.ParentHash {
t.Fatalf("Parent hash [%v]: Parent hash not found", block1.ParentHash().String())
}
if block1.UncleHash().String() != data.UncleHash {
t.Fatalf("Uncle hash [%v]: Uncle hash not found", block1.UncleHash().String())
}
if block1.Size().String() != data.Size {
t.Fatalf("Size [%v]: Size not found", block1.Size().String())
}
if block1.Nonce() != data.Nonce {
t.Fatalf("Block nonce [%v]: Block nonce not found", block1.Nonce())
}
if getAllBlocks := core.SGetAllBlocks(sqldb); len(getAllBlocks) == 0 {
t.Fatalf("GetAllBlocks [%v]: GetAllBlocks did not return correctly", getAllBlocks)
}
if getAllBlocksMinedByAddress := core.SGetAllBlocksMinedByAddress(sqldb, block1.Coinbase().String()); len(getAllBlocksMinedByAddress) == 0 {
t.Fatalf("GetAllBlocksMinedByAddress [%v]: GetAllBlocksMinedByAddress did not return correctly", getAllBlocksMinedByAddress)
}
})
t.Run("TestGetRecentBlock", func(t *testing.T) {
response := core.SGetRecentBlock(sqldb)
byteRes := []byte(response)
var recentBlock core.SBlock
json.Unmarshal(byteRes, &recentBlock)
if block.Hash().String() != recentBlock.Hash {
t.Fatalf("Block Hash [%v]: Block hash not found", block.Hash().String())
if block1.Hash().String() != recentBlock.Hash {
t.Fatalf("Block Hash [%v]: Block hash not found", block1.Hash().String())
}
if block.Coinbase().String() != recentBlock.Coinbase {
t.Fatalf("Block coinbase [%v]: Block coinbase not found", block.Coinbase().String())
if block1.Coinbase().String() != recentBlock.Coinbase {
t.Fatalf("Block coinbase [%v]: Block coinbase not found", block1.Coinbase().String())
}
if block.Number().String() != recentBlock.Number {
t.Fatalf("Block number [%v]: Block number not found", block.Number().String())
if block1.Number().String() != recentBlock.Number {
t.Fatalf("Block number [%v]: Block number not found", block1.Number().String())
}
if block.GasUsed() != recentBlock.GasUsed {
t.Fatalf("Gas Used [%v]: Gas used not found", block.GasUsed())
if block1.GasUsed() != recentBlock.GasUsed {
t.Fatalf("Gas Used [%v]: Gas used not found", block1.GasUsed())
}
if block.GasLimit() != recentBlock.GasLimit {
t.Fatalf("Gas Limit [%v]: Gas limit not found", block.GasLimit())
if block1.GasLimit() != recentBlock.GasLimit {
t.Fatalf("Gas Limit [%v]: Gas limit not found", block1.GasLimit())
}
if block.Transactions().Len() != recentBlock.TxCount {
t.Fatalf("Tx Count [%v]: Tx Count not found", block.Transactions().Len())
if block1.Transactions().Len() != recentBlock.TxCount {
t.Fatalf("Tx Count [%v]: Tx Count not found", block1.Transactions().Len())
}
if len(block.Uncles()) != recentBlock.UncleCount {
t.Fatalf("Uncle count [%v]: Uncle count not found", len(block.Uncles()))
if len(block1.Uncles()) != recentBlock.UncleCount {
t.Fatalf("Uncle count [%v]: Uncle count not found", len(block1.Uncles()))
}
if block.ParentHash().String() != recentBlock.ParentHash {
t.Fatalf("Parent hash [%v]: Parent hash not found", block.ParentHash().String())
if block1.ParentHash().String() != recentBlock.ParentHash {
t.Fatalf("Parent hash [%v]: Parent hash not found", block1.ParentHash().String())
}
if block.UncleHash().String() != recentBlock.UncleHash {
t.Fatalf("Uncle hash [%v]: Uncle hash not found", block.UncleHash().String())
if block1.UncleHash().String() != recentBlock.UncleHash {
t.Fatalf("Uncle hash [%v]: Uncle hash not found", block1.UncleHash().String())
}
if block.Size().String() != recentBlock.Size {
t.Fatalf("Size [%v]: Size not found", block.Size().String())
if block1.Size().String() != recentBlock.Size {
t.Fatalf("Size [%v]: Size not found", block1.Size().String())
}
if block.Nonce() != recentBlock.Nonce {
t.Fatalf("Block nonce [%v]: Block nonce not found", block.Nonce())
if block1.Nonce() != recentBlock.Nonce {
t.Fatalf("Block nonce [%v]: Block nonce not found", block1.Nonce())
}
if allTxsFromBlock := core.SGetAllTransactionsFromBlock(sqldb, block2.Number().String()); len(allTxsFromBlock) == 0 {
t.Fatalf("GetAllTransactionsFromBlock [%v]: GetAllTransactionsFromBlock did not return correctly", allTxsFromBlock)
}
core.ClearTables()
})
t.Run("TestContractCreationTx", func(t *testing.T) {
key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
signer := types.NewEIP155Signer(big.NewInt(2147483647))
//Nonce,Value, GasLimit, Gasprice, data
contractCreation := types.NewContractCreation(1, big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11})
mytx, _ := types.SignTx(contractCreation, signer, key)
txs := []*types.Transaction{mytx}
receipt2 := &types.Receipt{
Status: types.ReceiptStatusSuccessful,
CumulativeGasUsed: 1,
Logs: []*types.Log{
{Address: common.BytesToAddress([]byte{0x11})},
{Address: common.BytesToAddress([]byte{0x01, 0x11})},
},
TxHash: common.BytesToHash([]byte{0x11, 0x11}),
ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}),
GasUsed: 111111,
}
receipts := []*types.Receipt{receipt2}
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)
}
var contractAddressFromReciept string
for _, receipt := range receipts {
contractAddressFromReciept = (*types.ReceiptForStorage)(receipt).ContractAddress.String()
}
sqldb, err := core.DBConnection()
if err != nil {
panic(err)
}
for _, tx := range txs {
for _, tx := range txs2 {
txn := core.SGetTransaction(sqldb, tx.Hash().String())
byt := []byte(txn)
var data core.ShyftTxEntryPretty
@ -283,14 +220,14 @@ func TestBlock(t *testing.T) {
if tx.GasPrice().Uint64() != data.GasPrice {
t.Fatalf("Gas Price [%v]: Gas price not found", tx.GasPrice().String())
}
if block.GasLimit() != data.GasLimit {
t.Fatalf("Gas Limit [%v]: Gas limit not found", block.GasLimit())
if block1.GasLimit() != data.GasLimit {
t.Fatalf("Gas Limit [%v]: Gas limit not found", block1.GasLimit())
}
if block.Hash().String() != data.BlockHash {
t.Fatalf("Block Hash [%v]: Block hash not found", block.Hash().String())
if block3.Hash().String() != data.BlockHash {
t.Fatalf("Block Hash [%v]: Block hash not found", block1.Hash().String())
}
if block.Number().String() != data.BlockNumber {
t.Fatalf("Block Number [%v]: Block number not found", block.Number().String())
if block3.Number().String() != data.BlockNumber {
t.Fatalf("Block Number [%v]: Block number not found", block1.Number().String())
}
if tx.Value().String() != data.Amount {
t.Fatalf("Amount [%v]: Amount not found", tx.Value().String())
@ -299,10 +236,10 @@ func TestBlock(t *testing.T) {
t.Fatalf("Cost [%v]: Cost not found", tx.Cost().String())
}
var status string
if receipt2.Status == 1 {
if receipt.Status == 1 {
status = "SUCCESS"
}
if receipt2.Status == 0 {
if receipt.Status == 0 {
status = "FAIL"
}
if status != data.Status {
@ -318,49 +255,9 @@ func TestBlock(t *testing.T) {
t.Fatalf("isContract [%v]: isContract bool is incorrect", isContract)
}
}
core.ClearTables()
})
//
t.Run("TestTransactionsToReturnTransactions", func(t *testing.T) {
key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
signer := types.NewEIP155Signer(big.NewInt(2147483647))
//Nonce, To Address,Value, GasLimit, Gasprice, data
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)
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)
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)
txs := []*types.Transaction{mytx, mytx2, mytx3}
receipt1 := &types.Receipt{
Status: types.ReceiptStatusSuccessful,
CumulativeGasUsed: 1,
Logs: []*types.Log{
{Address: common.BytesToAddress([]byte{0x11})},
{Address: common.BytesToAddress([]byte{0x01, 0x11})},
},
TxHash: common.BytesToHash([]byte{0x11, 0x11}),
ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}),
GasUsed: 111111,
}
receipts := []*types.Receipt{receipt1}
block := types.NewBlock(&types.Header{Number: big.NewInt(314)}, txs, nil, receipts)
sqldb, err := core.DBConnection()
if err != nil {
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 {
txn := core.SGetTransaction(sqldb, tx.Hash().String())
byt := []byte(txn)
@ -386,14 +283,14 @@ func TestBlock(t *testing.T) {
if tx.GasPrice().Uint64() != data.GasPrice {
t.Fatalf("Gas Price [%v]: Gas price not found", tx.GasPrice().String())
}
if block.GasLimit() != data.GasLimit {
t.Fatalf("Gas Limit [%v]: Gas limit not found", block.GasLimit())
if block1.GasLimit() != data.GasLimit {
t.Fatalf("Gas Limit [%v]: Gas limit not found", block1.GasLimit())
}
if block.Hash().String() != data.BlockHash {
t.Fatalf("Block Hash [%v]: Block hash not found", block.Hash().String())
if block1.Hash().String() != data.BlockHash {
t.Fatalf("Block Hash [%v]: Block hash not found", block1.Hash().String())
}
if block.Number().String() != data.BlockNumber {
t.Fatalf("Block Number [%v]: Block number not found", block.Number().String())
if block1.Number().String() != data.BlockNumber {
t.Fatalf("Block Number [%v]: Block number not found", block1.Number().String())
}
if tx.Value().String() != data.Amount {
t.Fatalf("Amount [%v]: Amount not found", tx.Value().String())
@ -402,10 +299,10 @@ func TestBlock(t *testing.T) {
t.Fatalf("Cost [%v]: Cost not found", tx.Cost().String())
}
var status string
if receipt1.Status == 1 {
if receipt.Status == 1 {
status = "SUCCESS"
}
if receipt1.Status == 0 {
if receipt.Status == 0 {
status = "FAIL"
}
if status != data.Status {
@ -425,53 +322,8 @@ func TestBlock(t *testing.T) {
if getAllTx := core.SGetAllTransactions(sqldb); len(getAllTx) == 0 {
t.Fatalf("GetAllTransactions [%v]: GetAllTransactions did not return correctly", getAllTx)
}
core.ClearTables()
})
t.Run("TestAccountsToReturnAccounts", func(t *testing.T) {
key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
signer := types.NewEIP155Signer(big.NewInt(2147483647))
sqldb, err := core.DBConnection()
if err != nil {
panic(err)
}
fromAddr := "0x71562b71999873db5b286df957af199ec94617f7"
fromAddrEndBalance := "35"
fromAddrEndNonce := "4"
core.CreateAccount(sqldb, fromAddr, "50", "1")
toAddr := common.BytesToAddress([]byte{0x11})
//Nonce, To Address,Value, GasLimit, Gasprice, data
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)
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)
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)
txs := []*types.Transaction{mytx, mytx2, mytx3}
receipt1 := &types.Receipt{
Status: types.ReceiptStatusSuccessful,
CumulativeGasUsed: 1,
Logs: []*types.Log{
{Address: common.BytesToAddress([]byte{0x11})},
{Address: common.BytesToAddress([]byte{0x01, 0x11})},
},
TxHash: common.BytesToHash([]byte{0x11, 0x11}),
ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}),
GasUsed: 111111,
}
receipts := []*types.Receipt{receipt1}
block := types.NewBlock(&types.Header{Number: big.NewInt(319)}, txs, nil, receipts)
if err := core.SWriteBlock(block, receipts); err != nil {
t.Fatalf("Failed to write block into database: %v", err)
}
for _, tx := range txs {
accountAddrTo := core.SGetAccount(sqldb, tx.To().String())
byts := []byte(accountAddrTo)
@ -508,7 +360,9 @@ func TestBlock(t *testing.T) {
if getAllAccounts := core.SGetAllAccounts(sqldb); len(getAllAccounts) == 0 {
t.Fatalf("GetAllAccounts [%v]: GetAllAccounts did not return correctly", getAllAccounts)
}
core.ClearTables()
})
core.ClearTables()
}
//Genesis.go functions
// WriteBlockZero
// WriteShyftGen