forked from ethereum-optimism/op-geth
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2734ce
commit 2c6394b
Showing
3 changed files
with
91 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ethapi | ||
|
||
import ( | ||
"errors" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/status-im/keycard-go/hexutils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_parseGasPriceMinimumUpdated(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
data []byte | ||
result *big.Int | ||
err error | ||
}{ | ||
{ | ||
name: "should parse gas price successfully", | ||
data: hexutils.HexToBytes("00000000000000000000000000000000000000000000000000000000000f4240"), | ||
result: big.NewInt(1_000_000), | ||
err: nil, | ||
}, | ||
{ | ||
name: "should return error if data is not in the expected format", | ||
data: hexutils.HexToBytes("12345"), | ||
result: nil, | ||
err: errors.New("abi: cannot marshal in to go type: length insufficient 3 require 32"), | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
result, err := parseGasPriceMinimumUpdated(test.data) | ||
assert.Equal(t, test.result, result) | ||
|
||
if test.err == nil { | ||
assert.NoError(t, err) | ||
} else { | ||
assert.EqualError(t, err, test.err.Error()) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package params | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"math/big" | ||
"testing" | ||
) | ||
|
||
func TestGasLimits_Limit(t *testing.T) { | ||
subTest := func(t *testing.T, name string, chainId uint64, limits []LimitChange) { | ||
t.Run(name, func(t *testing.T) { | ||
for i, l := range limits { | ||
beginningHeight := l.block | ||
beginningLimit := PreGingerbreadNetworkGasLimits[chainId].Limit(beginningHeight) | ||
assert.Equal(t, l.gasLimit, beginningLimit, "gas limit at block %d (%s)", beginningHeight, name) | ||
|
||
if i < len(limits)-1 { | ||
endHeight := new(big.Int).Sub(limits[i+1].block, big.NewInt(1)) | ||
endLimit := PreGingerbreadNetworkGasLimits[chainId].Limit(endHeight) | ||
assert.Equal(t, l.gasLimit, endLimit, "gas limit at block %d (%s)", endHeight, name) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
subTest(t, "mainnet", CeloMainnetChainID, mainnetGasLimits.changes) | ||
subTest(t, "alfajores", CeloAlfajoresChainID, alfajoresGasLimits.changes) | ||
subTest(t, "baklava", CeloBaklavaChainID, baklavaGasLimits.changes) | ||
} |