Skip to content

Commit

Permalink
Merge branch 'develop' into c/geth-tests-block-granularty
Browse files Browse the repository at this point in the history
  • Loading branch information
cabrador authored Oct 8, 2024
2 parents b6c59a3 + 20786a5 commit 86227b6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
3 changes: 1 addition & 2 deletions ethtest/block_enviroment.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
)

type stBlockEnvironment struct {
blockNumber uint64
Coinbase common.Address `json:"currentCoinbase" gencodec:"required"`
Random *BigInt `json:"currentRandom" gencodec:"optional"`
Difficulty *BigInt `json:"currentDifficulty" gencodec:"optional"`
Expand Down Expand Up @@ -74,7 +73,7 @@ func (s *stBlockEnvironment) GetGasLimit() uint64 {
}

func (s *stBlockEnvironment) GetNumber() uint64 {
return s.blockNumber
return s.Number.Uint64()
}

func (s *stBlockEnvironment) GetTimestamp() uint64 {
Expand Down
19 changes: 15 additions & 4 deletions ethtest/block_enviroment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func TestStBlockEnvironment_GetBaseFee(t *testing.T) {
}

func TestStBlockEnvironment_GetBlockHash_Correctly_Converts(t *testing.T) {
blockNum := uint64(10)
want := common.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(blockNum)).String())))
env := &stBlockEnvironment{blockNumber: blockNum}
blockNum := int64(10)
want := common.BytesToHash(crypto.Keccak256([]byte(big.NewInt(blockNum).String())))
env := &stBlockEnvironment{Number: newBigInt(blockNum)}

got, err := env.GetBlockHash(blockNum)
got, err := env.GetBlockHash(uint64(blockNum))
if err != nil {
t.Fatalf("cannot get block hash: %v", err)
}
Expand Down Expand Up @@ -186,3 +186,14 @@ func TestStBlockEnvironment_GetBlobBaseFee(t *testing.T) {
})
}
}

func TestStBlockEnvironment_CorrectBlockNumberIsReturned(t *testing.T) {
blkNumber := uint64(1)
env := &stBlockEnvironment{
Number: newBigInt(int64(blkNumber)),
}

if got, want := env.GetNumber(), blkNumber; got != want {
t.Errorf("unexpected block number, got: %v, want: %v", got, want)
}
}
28 changes: 13 additions & 15 deletions ethtest/mock_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ func CreateTestTransaction(t *testing.T) txcontext.TxContext {
to := common.HexToAddress("0x10")
return &stateTestContext{
env: &stBlockEnvironment{
blockNumber: 1,
Coinbase: common.Address{},
Difficulty: newBigInt(1),
GasLimit: newBigInt(1),
Number: newBigInt(1),
Timestamp: newBigInt(1),
BaseFee: newBigInt(1),
chainCfg: chainCfg,
Coinbase: common.Address{},
Difficulty: newBigInt(1),
GasLimit: newBigInt(1),
Number: newBigInt(1),
Timestamp: newBigInt(1),
BaseFee: newBigInt(1),
chainCfg: chainCfg,
},
inputState: types.GenesisAlloc{
common.HexToAddress("0x1"): core.GenesisAccount{
Expand Down Expand Up @@ -83,13 +82,12 @@ func CreateTestStJson(*testing.T) *stJSON {
return &stJSON{
path: "test/path",
Env: stBlockEnvironment{
blockNumber: 1,
Coinbase: common.Address{0x1},
Difficulty: newBigInt(1),
GasLimit: newBigInt(1),
Number: newBigInt(1),
Timestamp: newBigInt(1),
BaseFee: newBigInt(1),
Coinbase: common.Address{0x1},
Difficulty: newBigInt(1),
GasLimit: newBigInt(1),
Number: newBigInt(1),
Timestamp: newBigInt(1),
BaseFee: newBigInt(1),
},
Pre: types.GenesisAlloc{common.Address{0x2}: types.Account{
Code: []byte{1},
Expand Down

0 comments on commit 86227b6

Please sign in to comment.