mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
tmp
This commit is contained in:
parent
71cf9acfd6
commit
42183a4580
2 changed files with 60 additions and 28 deletions
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
Rewards "github.com/ethereum/go-ethereum/consensus/ethash"
|
Rewards "github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"github.com/ethereum/go-ethereum/shyfttracerinterface"
|
"github.com/ethereum/go-ethereum/shyfttracerinterface"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var IShyftTracer shyfttracerinterface.IShyftTracer
|
var IShyftTracer shyfttracerinterface.IShyftTracer
|
||||||
|
|
@ -300,9 +301,11 @@ func swriteBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive,
|
||||||
Amount: tx.Value().String(),
|
Amount: tx.Value().String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("TO", sendAndReceiveData.To)
|
||||||
|
fmt.Println("FROM", sendAndReceiveData.From)
|
||||||
getAccountBalanceReceiver := SGetAccount(sqldb, sendAndReceiveData.To)
|
getAccountBalanceReceiver := SGetAccount(sqldb, sendAndReceiveData.To)
|
||||||
getAccountBalanceSender:= SGetAccount(sqldb, sendAndReceiveData.From)
|
getAccountBalanceSender:= SGetAccount(sqldb, sendAndReceiveData.From)
|
||||||
|
fmt.Println("HERE", getAccountBalanceReceiver)
|
||||||
var receiverData SendAndReceive
|
var receiverData SendAndReceive
|
||||||
if err := json.Unmarshal([]byte(getAccountBalanceReceiver), &receiverData); err != nil {
|
if err := json.Unmarshal([]byte(getAccountBalanceReceiver), &receiverData); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
@ -410,3 +413,14 @@ func sstoreReward(sqldb *sql.DB, address string, reward *big.Int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func CreateAccount (sqldb *sql.DB, addr string, amount uint64, accountNonce uint64) {
|
||||||
|
|
||||||
|
sqlStatement := `INSERT INTO accounts(addr, balance, accountNonce) VALUES(($1), ($2), ($3)) RETURNING addr`
|
||||||
|
insertErr := sqldb.QueryRow(sqlStatement, addr, amount, accountNonce).Scan(&addr)
|
||||||
|
if insertErr != nil {
|
||||||
|
panic(insertErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"strconv"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -425,12 +424,29 @@ 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))
|
||||||
|
|
||||||
|
toAddr1 := common.BytesToAddress([]byte{0x11})
|
||||||
|
toAddr2 := common.BytesToAddress([]byte{0x22})
|
||||||
|
toAddr3 := common.BytesToAddress([]byte{0x33})
|
||||||
|
|
||||||
|
toAmount1 := big.NewInt(111)
|
||||||
|
var toAmountPrev1 uint64 = 3968686868
|
||||||
|
|
||||||
|
sqldb, err := core.DBConnection()
|
||||||
|
if (err != nil) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
core.CreateAccount(sqldb, toAddr1.Hex(), toAmountPrev1, 1)
|
||||||
|
core.CreateAccount(sqldb, toAddr2.Hex(), 423798729847, 1)
|
||||||
|
core.CreateAccount(sqldb, toAddr3.Hex(), 0, 1)
|
||||||
|
core.CreateAccount(sqldb, "0x71562b71999873DB5b286dF957af199Ec94617F7", 3968686868, 1)
|
||||||
|
|
||||||
//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, toAddr1, toAmount1, 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, toAddr2, big.NewInt(222), 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, toAddr3, big.NewInt(333), 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}
|
||||||
|
|
||||||
|
|
@ -452,37 +468,39 @@ t.Run("TestAccountsToReturnAccounts",func(t *testing.T) {
|
||||||
t.Fatalf("Failed to write block into database: %v", err)
|
t.Fatalf("Failed to write block into database: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sqldb, err := core.DBConnection()
|
if toAddr1.String() != tx1.To().String() {
|
||||||
if (err != nil) {
|
t.Fatalf("To address [%v]: To address not found", toAddr1.String())
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
accountAddrTo := core.SGetAccount(sqldb, toAddr1.String())
|
||||||
|
|
||||||
|
|
||||||
for _, tx := range txs {
|
|
||||||
accountAddrTo := core.SGetAccount(sqldb, tx.To().String())
|
|
||||||
byts := []byte(accountAddrTo)
|
|
||||||
var accountDataTo core.SAccounts
|
|
||||||
json.Unmarshal(byts, &accountDataTo)
|
|
||||||
|
|
||||||
if tx.To().String() != accountDataTo.Addr {
|
//for _, tx := range txs {
|
||||||
t.Fatalf("To address [%v]: To address not found", accountDataTo.Addr)
|
// accountAddrTo := core.SGetAccount(sqldb, tx.To().String())
|
||||||
}
|
// byts := []byte(accountAddrTo)
|
||||||
if tx.Value().String() != accountDataTo.Balance {
|
// var accountDataTo core.SAccounts
|
||||||
t.Fatalf("To address balance [%v]: To address balance not found", accountDataTo.Balance)
|
// json.Unmarshal(byts, &accountDataTo)
|
||||||
}
|
//
|
||||||
if strconv.FormatUint(tx.Nonce(), 10) != accountDataTo.AccountNonce {
|
// if tx.To().String() != accountDataTo.Addr {
|
||||||
t.Fatalf("To account nonce [%v]: To account nonce not found", accountDataTo.AccountNonce)
|
// t.Fatalf("To address [%v]: To address not found", accountDataTo.Addr)
|
||||||
}
|
// }
|
||||||
if getAllAccountTxs := core.SGetAccountTxs(sqldb, tx.To().String()); len(getAllAccountTxs) == 0 {
|
// if tx.Value().String() != accountDataTo.Balance {
|
||||||
t.Fatalf("GetAccountTxs [%v]: GetAccountTxs did not return correctly", getAllAccountTxs)
|
// t.Fatalf("To address balance [%v]: To address balance not found", accountDataTo.Balance)
|
||||||
}
|
// }
|
||||||
}
|
// if strconv.FormatUint(tx.Nonce(), 10) != accountDataTo.AccountNonce {
|
||||||
|
// t.Fatalf("To account nonce [%v]: To account nonce not found", accountDataTo.AccountNonce)
|
||||||
|
// }
|
||||||
|
// if getAllAccountTxs := core.SGetAccountTxs(sqldb, tx.To().String()); len(getAllAccountTxs) == 0 {
|
||||||
|
// t.Fatalf("GetAccountTxs [%v]: GetAccountTxs did not return correctly", getAllAccountTxs)
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
if getAllAccounts := core.SGetAllAccounts(sqldb); len(getAllAccounts) == 0 {
|
if getAllAccounts := core.SGetAllAccounts(sqldb); len(getAllAccounts) == 0 {
|
||||||
t.Fatalf("GetAllAccounts [%v]: GetAllAccounts did not return correctly", getAllAccounts)
|
t.Fatalf("GetAllAccounts [%v]: GetAllAccounts did not return correctly", getAllAccounts)
|
||||||
}
|
}
|
||||||
ClearTables()
|
//ClearTables()
|
||||||
})
|
})
|
||||||
|
|
||||||
ClearTables()
|
//ClearTables()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue