mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
c1f848746d
* Consensus tests update 11 * Add GrayGlacier fork * Wire currentRandom from tests into PREVRANDAO * Serenity engine * Support insertion of PoS blocks in MockSentry * Introduce marshallTypedTransactionsAsRlpStrings arg into (*Block) RawBody() * Revert "Introduce marshallTypedTransactionsAsRlpStrings arg into (*Block) RawBody()" This reverts commit 903fca572be03c7de33318ce177a03a4be34927b. * Post-merge fix * Don't wait for Beacon Chain in tests * Skip powToPosBlockRejection transition test * ForkChoice in insertPoSBlocks * Add withPosDownloader arg to MockWithEverything in order to fix TestPoSDownloader
94 lines
2.6 KiB
Go
94 lines
2.6 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"math"
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/holiman/uint256"
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
"github.com/ledgerwatch/erigon-lib/kv/kvcache"
|
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
"github.com/ledgerwatch/erigon/core"
|
|
"github.com/ledgerwatch/erigon/core/types"
|
|
"github.com/ledgerwatch/erigon/crypto"
|
|
"github.com/ledgerwatch/erigon/params"
|
|
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
|
|
"github.com/ledgerwatch/erigon/turbo/stages"
|
|
)
|
|
|
|
func TestGasPrice(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
description string
|
|
chainSize int
|
|
expectedPrice *big.Int
|
|
}{
|
|
{
|
|
description: "standard settings 60 blocks",
|
|
chainSize: 60,
|
|
expectedPrice: big.NewInt(params.GWei * int64(36)),
|
|
},
|
|
{
|
|
description: "standard settings 30 blocks",
|
|
chainSize: 30,
|
|
expectedPrice: big.NewInt(params.GWei * int64(18)),
|
|
},
|
|
}
|
|
|
|
for _, testCase := range cases {
|
|
t.Run(testCase.description, func(t *testing.T) {
|
|
db := createGasPriceTestKV(t, testCase.chainSize)
|
|
defer db.Close()
|
|
stateCache := kvcache.New(kvcache.DefaultCoherentConfig)
|
|
base := NewBaseApi(nil, stateCache, snapshotsync.NewBlockReader(), false)
|
|
eth := NewEthAPI(base, db, nil, nil, nil, 5000000)
|
|
|
|
ctx := context.Background()
|
|
result, err := eth.GasPrice(ctx)
|
|
if err != nil {
|
|
t.Fatalf("error getting gas price: %s", err)
|
|
}
|
|
|
|
if testCase.expectedPrice.Cmp(result.ToInt()) != 0 {
|
|
t.Fatalf("gas price mismatch, want %d, got %d", testCase.expectedPrice, result.ToInt())
|
|
}
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
func createGasPriceTestKV(t *testing.T, chainSize int) kv.RwDB {
|
|
var (
|
|
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
|
addr = crypto.PubkeyToAddress(key.PublicKey)
|
|
gspec = &core.Genesis{
|
|
Config: params.TestChainConfig,
|
|
Alloc: core.GenesisAlloc{addr: {Balance: big.NewInt(math.MaxInt64)}},
|
|
}
|
|
signer = types.LatestSigner(gspec.Config)
|
|
)
|
|
m := stages.MockWithGenesis(t, gspec, key, false)
|
|
|
|
// Generate testing blocks
|
|
chain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, chainSize, func(i int, b *core.BlockGen) {
|
|
b.SetCoinbase(common.Address{1})
|
|
tx, txErr := types.SignTx(types.NewTransaction(b.TxNonce(addr), common.HexToAddress("deadbeef"), uint256.NewInt(100), 21000, uint256.NewInt(uint64(int64(i+1)*params.GWei)), nil), *signer, key)
|
|
if txErr != nil {
|
|
t.Fatalf("failed to create tx: %v", txErr)
|
|
}
|
|
b.AddTx(tx)
|
|
}, false)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
// Construct testing chain
|
|
if err = m.InsertChain(chain); err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
return m.DB
|
|
}
|