Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented GetHeaderByNumber and GetHeaderByHash #149

Merged
merged 29 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
07ada94
implemented methods: eth_getHeaderByNumber
novosandara Mar 8, 2024
22a5ece
The following methods were created: eth_createAccessList, eth_coinbas…
novosandara Mar 10, 2024
202ae4a
fix lint
novosandara Mar 10, 2024
c3cbd86
CR fix, part 1
novosandara Mar 11, 2024
8df5959
CR fix, part 2
novosandara Mar 12, 2024
d07f2e4
lint fix
novosandara Mar 12, 2024
b0115c6
Merge branch 'develop' into implementing_methods_eth_txpool
novosandara Mar 14, 2024
1fc6f10
created UTs for methods: eth_createAccessList, eth_getBlockReceipts, …
novosandara Mar 14, 2024
681665b
e2e test for eth_getBlockReceipts
novosandara Mar 14, 2024
297ea34
Merge branch 'develop' into implementing_methods_eth_txpool
novosandara Mar 14, 2024
c7960fe
e2e remove
novosandara Mar 15, 2024
5847e35
Merge branch 'develop' into implementing_methods_eth_txpool
novosandara Mar 15, 2024
775749e
Merge branch 'develop' into implementing_methods_eth_txpool
novosandara Mar 18, 2024
ace4b58
CR fix
novosandara Mar 19, 2024
4ece04e
Remove dummy comment
Stefan-Ethernal Mar 20, 2024
29f7454
Merge branch 'develop' into implementing_methods_eth_txpool
novosandara Mar 20, 2024
a2ce3d5
CR fix
novosandara Mar 20, 2024
8df9653
lint fix
novosandara Mar 22, 2024
e1bbc87
Merge branch 'develop' into implementing_methods_eth_txpool
novosandara Mar 22, 2024
6f9b1d3
CR fix and new tests e2e have been added
novosandara Mar 25, 2024
fe5e7f0
Merge branch 'develop' into implementing_methods_eth_txpool
novosandara Mar 25, 2024
685e4e0
Address comments
Stefan-Ethernal Mar 26, 2024
b95b8f4
Minor simplification
Stefan-Ethernal Mar 26, 2024
845579b
Minor changes in eth_getBlockReceipts
Stefan-Ethernal Mar 26, 2024
fb0ee29
e2e test fix and cr fix
novosandara Mar 26, 2024
469ca4f
lint fix
novosandara Mar 26, 2024
329f1b9
e2e
novosandara Mar 26, 2024
3421560
Merge branch 'develop' into implementing_methods_eth_txpool
novosandara Mar 26, 2024
1295b73
Merge branch 'develop' into implementing_methods_eth_txpool
novosandara Mar 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion e2e-polybft/e2e/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ func TestE2E_Bridge_RootchainTokensTransfers(t *testing.T) {
framework.WithBridge(),
framework.WithSecretsCallback(func(addrs []types.Address, tcc *framework.TestClusterConfig) {
for i := 0; i < len(addrs); i++ {
tcc.StakeAmounts = append(tcc.StakeAmounts, ethgo.Ether(10))
// premine receivers, so that they are able to do withdrawals
tcc.StakeAmounts = append(tcc.StakeAmounts, ethgo.Ether(10))
}

tcc.Premine = append(tcc.Premine, receivers...)
}))

defer cluster.Stop()

cluster.WaitForReady(t)
Expand Down Expand Up @@ -1345,6 +1346,7 @@ func TestE2E_Bridge_NonMintableERC20Token_WithPremine(t *testing.T) {
checkBalancesFn(types.Address(rewardWalletKey.Address()), bigZero, command.DefaultPremineBalance, true)

validatorsExpectedBalance := new(big.Int).Sub(command.DefaultPremineBalance, command.DefaultStake)

for _, server := range cluster.Servers {
validatorAccount, err := validatorHelper.GetAccountFromDir(server.DataDir())
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions e2e-polybft/e2e/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ func TestE2E_Consensus_MintableERC20NativeToken(t *testing.T) {
config.Premine = append(config.Premine, fmt.Sprintf("%s:%d", addr, initValidatorsBalance))
config.StakeAmounts = append(config.StakeAmounts, new(big.Int).Set(initValidatorsBalance))
validatorsAddrs[i] = addr

initialTotalSupply.Add(initialTotalSupply, initValidatorsBalance)
}
}))
Expand Down
52 changes: 51 additions & 1 deletion e2e-polybft/e2e/jsonrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func TestE2E_JsonRPC(t *testing.T) {
Value: newBalance,
})
require.NoError(t, err)

txPrice := gasPrice * estimatedGas
// subtract gasPrice * estimatedGas from the balance and transfer the rest to the other account
// in order to leave no funds on the account
Expand Down Expand Up @@ -413,11 +414,60 @@ func TestE2E_JsonRPC(t *testing.T) {
require.NotEqual(t, ethTxn.From, ethgo.ZeroAddress)
})

t.Run("eth_getHeaderByNumber", func(t *testing.T) {
key1, err := crypto.GenerateECDSAKey()
require.NoError(t, err)

txn := cluster.Transfer(t, senderKey, key1.Address(), one)
require.NoError(t, txn.Wait())
require.True(t, txn.Succeed())
txReceipt := txn.Receipt()

var header types.Header
err = jsonRPC.Call("eth_getHeaderByNumber", &header, ethgo.BlockNumber(txReceipt.BlockNumber))
require.NoError(t, err)

require.Equal(t, txReceipt.BlockNumber, header.Number)
require.Equal(t, txReceipt.BlockHash, header.Hash)
})

t.Run("eth_getHeaderByHash", func(t *testing.T) {
key1, err := crypto.GenerateECDSAKey()
require.NoError(t, err)

txn := cluster.Transfer(t, senderKey, key1.Address(), one)
require.NoError(t, txn.Wait())
require.True(t, txn.Succeed())
txReceipt := txn.Receipt()

var header types.Header
err = jsonRPC.Call("eth_getHeaderByHash", &header, txReceipt.BlockHash)
require.NoError(t, err)

require.Equal(t, txReceipt.BlockNumber, header.Number)
require.Equal(t, txReceipt.BlockHash, header.Hash)
})

t.Run("txpool_contentFrom", func(t *testing.T) {
key1, err := crypto.GenerateECDSAKey()
require.NoError(t, err)

txn := cluster.Transfer(t, senderKey, key1.Address(), one)
require.NoError(t, txn.Wait())
require.True(t, txn.Succeed())
txReceipt := txn.Receipt()

var contentFrom map[uint64]*ethgo.Transaction
err = jsonRPC.Call("txpool_contentFrom", &contentFrom, key1.Address())
require.NoError(t, err)

require.Equal(t, txReceipt.TransactionHash, contentFrom[txn.Txn().Nonce()].Hash)
})

t.Run("debug_traceTransaction", func(t *testing.T) {
key1, err := crypto.GenerateECDSAKey()
require.NoError(t, err)

// Test. We should be able to query the transaction by its hash
txn := cluster.Transfer(t, senderKey, key1.Address(), one)
require.NoError(t, txn.Wait())
require.True(t, txn.Succeed())
Expand Down
3 changes: 3 additions & 0 deletions e2e-polybft/e2e/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ func TestE2E_TxPool_Transfer(t *testing.T) {
if err != nil {
return true
}

t.Logf("Balance %s %s", receiver, balance)

if balance.Uint64() != uint64(sendAmount) {
return false
}
Expand Down Expand Up @@ -295,6 +297,7 @@ func TestE2E_TxPool_BroadcastTransactions(t *testing.T) {
for _, srv := range cluster.Servers {
balance, err := srv.WaitForNonZeroBalance(ethgo.Address(recipient), time.Second*10)
assert.NoError(t, err)

if balance != nil && balance.BitLen() > 0 {
assert.Equal(t, sentAmount, balance)
} else {
Expand Down
3 changes: 3 additions & 0 deletions e2e-polybft/property/property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ func TestProperty_DropValidators(t *testing.T) {
// check that block production is stoped
currentBlock, err = activeValidator.JSONRPC().Eth().BlockNumber()
require.NoError(t, err)

oldBlockNumber := currentBlock

time.Sleep(2 * blockTime)

currentBlock, err = activeValidator.JSONRPC().Eth().BlockNumber()
require.NoError(t, err)
require.Equal(t, oldBlockNumber, currentBlock)
Expand Down
2 changes: 2 additions & 0 deletions jsonrpc/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ func TestBlockNumberOrHash_UnmarshalJSON(t *testing.T) {
assert.Error(t, err)
} else {
assert.NoError(t, err)

if tt.expectedBnh.BlockNumber != nil {
assert.Equal(t, *bnh.BlockNumber, *tt.expectedBnh.BlockNumber)
}

if tt.expectedBnh.BlockHash != nil {
assert.Equal(t, bnh.BlockHash.String(), tt.expectedBnh.BlockHash.String())
}
Expand Down
1 change: 1 addition & 0 deletions jsonrpc/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func (d *Dispatcher) handleSubscribe(req Request, conn wsConn) (string, Error) {
if err != nil {
return "", NewInternalError(err.Error())
}

filterID = d.filterManager.NewLogFilter(logQuery, conn)
} else if subscribeMethod == "newPendingTransactions" {
filterID = d.filterManager.NewPendingTxFilter(conn)
Expand Down
4 changes: 4 additions & 0 deletions jsonrpc/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,20 +467,24 @@ func TestDispatcherBatchRequest(t *testing.T) {
assert.Equal(t, c.err, resp.Error)
} else {
var batchResp []SuccessResponse

assert.NoError(t, expectBatchJSONResult(res, &batchResp))

if c.name == "leading-whitespace" {
assert.Len(t, batchResp, 4)

for index, resp := range batchResp {
assert.Equal(t, c.batchResponse[index].Error, resp.Error)
}
} else if c.name == "valid-batch-req" {
assert.Len(t, batchResp, 6)

for index, resp := range batchResp {
assert.Equal(t, c.batchResponse[index].Error, resp.Error)
}
} else if c.name == "no-limits" {
assert.Len(t, batchResp, 12)

for index, resp := range batchResp {
assert.Equal(t, c.batchResponse[index].Error, resp.Error)
}
Expand Down
Loading
Loading