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

test to ensure DIFFICULTY/PREVRANDAO opcode returns the expected value of 1 #1667

Merged
merged 28 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d02469c
test to ensure DIFFICULTY/PREVRANDAO opcode returns the expected valu…
amsanghi May 25, 2023
31a0a67
Fix contracts branch
amsanghi May 25, 2023
ccf472d
Fix contracts branch
amsanghi May 25, 2023
9b632f9
update submodules
amsanghi May 25, 2023
442aa7c
Merge branch 'master' into test_PREVRANDAO
amsanghi May 25, 2023
e7220b6
update submodules
amsanghi May 25, 2023
f57855c
Merge branch 'master' into test_PREVRANDAO
amsanghi May 30, 2023
1d3a93c
Changes based on PR comments
amsanghi May 30, 2023
dc01bf6
Merge branch 'master' into test_PREVRANDAO
amsanghi Jun 21, 2023
b517b8e
Changes based on PR comments
amsanghi Jun 21, 2023
37ff4e7
minor fix
amsanghi Jun 21, 2023
bc8e7bb
Changes based on PR comments
amsanghi Jun 21, 2023
025ae7c
Merge branch 'master' into test_PREVRANDAO
amsanghi Sep 29, 2023
b725fec
Changes based on PR comments
amsanghi Sep 29, 2023
1b76e9e
Changes based on PR comments
amsanghi Oct 25, 2023
12b5a71
Merge branch 'master' into test_PREVRANDAO
amsanghi Oct 25, 2023
b0c0db9
update contract
amsanghi Oct 25, 2023
9067c64
minor fix
amsanghi Oct 25, 2023
35b4bcf
update contract
amsanghi Oct 25, 2023
17ce3cc
update contract
amsanghi Oct 25, 2023
46287a1
minor fix
amsanghi Oct 25, 2023
b5383bd
changes based on pr comments
amsanghi Oct 26, 2023
ba0de15
update block validator test
amsanghi Oct 26, 2023
0b8fdaa
Merge branch 'master' into test_PREVRANDAO
amsanghi Nov 28, 2023
5a47889
minor fix
amsanghi Nov 28, 2023
b4a3e2e
Merge branch 'master' into test_PREVRANDAO
amsanghi Nov 28, 2023
d9aa22a
Merge branch 'master' into test_PREVRANDAO
joshuacolvin0 Nov 28, 2023
ceaaa6a
Merge branch 'master' into test_PREVRANDAO
joshuacolvin0 Nov 28, 2023
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
2 changes: 1 addition & 1 deletion contracts
30 changes: 29 additions & 1 deletion system_tests/block_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
Expand All @@ -22,7 +23,9 @@ import (
"github.com/offchainlabs/nitro/arbos/l2pricing"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/execution/gethexec"
"github.com/offchainlabs/nitro/solgen/go/mocksgen"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/util/arbmath"
)

type workloadType uint
Expand Down Expand Up @@ -68,6 +71,7 @@ func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops

perTransfer := big.NewInt(1e12)

var simple *mocksgen.Simple
if workload != upgradeArbOs {
for i := 0; i < workloadLoops; i++ {
var tx *types.Transaction
Expand Down Expand Up @@ -119,10 +123,24 @@ func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops
}
} else {
auth := l2info.GetDefaultTransactOpts("Owner", ctx)
// deploy a test contract
var err error
_, _, simple, err = mocksgen.DeploySimple(&auth, l2client)
Require(t, err, "could not deploy contract")

tx, err := simple.StoreDifficulty(&auth)
Require(t, err)
_, err = EnsureTxSucceeded(ctx, l2client, tx)
Require(t, err)
difficulty, err := simple.GetBlockDifficulty(&bind.CallOpts{})
amsanghi marked this conversation as resolved.
Show resolved Hide resolved
Require(t, err)
if !arbmath.BigEquals(difficulty, common.Big1) {
Fatal(t, "Expected difficulty to be 1 but got:", difficulty)
}
// make auth a chain owner
arbDebug, err := precompilesgen.NewArbDebug(common.HexToAddress("0xff"), l2client)
Require(t, err)
tx, err := arbDebug.BecomeChainOwner(&auth)
tx, err = arbDebug.BecomeChainOwner(&auth)
Require(t, err)
_, err = EnsureTxSucceeded(ctx, l2client, tx)
Require(t, err)
Expand All @@ -133,6 +151,16 @@ func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops
_, err = EnsureTxSucceeded(ctx, l2client, tx)
Require(t, err)

tx, err = simple.StoreDifficulty(&auth)
Require(t, err)
_, err = EnsureTxSucceeded(ctx, l2client, tx)
Require(t, err)
difficulty, err = simple.GetBlockDifficulty(&bind.CallOpts{})
Require(t, err)
if !arbmath.BigEquals(difficulty, common.Big1) {
Fatal(t, "Expected difficulty to be 1 but got:", difficulty)
}

tx = l2info.PrepareTxTo("Owner", nil, l2info.TransferGas, perTransfer, []byte{byte(vm.PUSH0)})
err = l2client.SendTransaction(ctx, tx)
Require(t, err)
Expand Down
13 changes: 7 additions & 6 deletions system_tests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (b *NodeBuilder) Build(t *testing.T) func() {
} else {
l2 := NewTestClient(b.ctx)
b.L2Info, l2.ConsensusNode, l2.Client =
CreateTestL2WithConfig(t, b.ctx, b.L2Info, b.nodeConfig, b.execConfig, b.takeOwnership)
CreateTestL2WithConfig(t, b.ctx, b.L2Info, b.nodeConfig, b.execConfig, b.takeOwnership, b.chainConfig)
b.L2 = l2
}
b.L2.ExecNode = getExecNode(t, b.L2.ConsensusNode)
Expand Down Expand Up @@ -797,24 +797,26 @@ func createTestNodeOnL1WithConfigImpl(
// L2 -Only. Enough for tests that needs no interface to L1
// Requires precompiles.AllowDebugPrecompiles = true
func CreateTestL2(t *testing.T, ctx context.Context) (*BlockchainTestInfo, *arbnode.Node, *ethclient.Client) {
return CreateTestL2WithConfig(t, ctx, nil, nil, nil, true)
return CreateTestL2WithConfig(t, ctx, nil, nil, nil, true, nil)
}

func CreateTestL2WithConfig(
t *testing.T, ctx context.Context, l2Info *BlockchainTestInfo, nodeConfig *arbnode.Config, execConfig *gethexec.Config, takeOwnership bool,
t *testing.T, ctx context.Context, l2Info *BlockchainTestInfo, nodeConfig *arbnode.Config, execConfig *gethexec.Config, takeOwnership bool, chainConfig *params.ChainConfig,
) (*BlockchainTestInfo, *arbnode.Node, *ethclient.Client) {
if nodeConfig == nil {
nodeConfig = arbnode.ConfigDefaultL2Test()
}
if execConfig == nil {
execConfig = gethexec.ConfigDefaultTest()
}

if chainConfig == nil {
chainConfig = params.ArbitrumDevTestChainConfig()
}
feedErrChan := make(chan error, 10)

AddDefaultValNode(t, ctx, nodeConfig, true)

l2info, stack, chainDb, arbDb, blockchain := createL2BlockChain(t, l2Info, "", params.ArbitrumDevTestChainConfig(), &execConfig.Caching)
l2info, stack, chainDb, arbDb, blockchain := createL2BlockChain(t, l2Info, "", chainConfig, &execConfig.Caching)

Require(t, execConfig.Validate())
execConfigFetcher := func() *gethexec.Config { return execConfig }
Expand All @@ -823,7 +825,6 @@ func CreateTestL2WithConfig(

currentNode, err := arbnode.CreateNode(ctx, stack, execNode, arbDb, NewFetcherFromConfig(nodeConfig), blockchain.Config(), nil, nil, nil, nil, nil, feedErrChan)
Require(t, err)

// Give the node an init message
err = currentNode.TxStreamer.AddFakeInitMessage()
Require(t, err)
Expand Down
2 changes: 1 addition & 1 deletion system_tests/contract_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestContractTxDeploy(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
l2info, node, client := CreateTestL2WithConfig(t, ctx, nil, nil, nil, false)
l2info, node, client := CreateTestL2WithConfig(t, ctx, nil, nil, nil, false, nil)
defer node.StopAndWait()

from := common.HexToAddress("0x123412341234")
Expand Down
51 changes: 51 additions & 0 deletions system_tests/estimation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package arbtest

import (
"context"
"github.com/offchainlabs/nitro/arbnode"
"math/big"
"testing"

Expand Down Expand Up @@ -127,6 +128,56 @@ func TestEstimate(t *testing.T) {
}
}

func TestDifficultyForLatestArbOS(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

l2info, node, client := CreateTestL2(t, ctx)
defer node.StopAndWait()

auth := l2info.GetDefaultTransactOpts("Owner", ctx)

// deploy a test contract
_, _, simple, err := mocksgen.DeploySimple(&auth, client)
Require(t, err, "could not deploy contract")

tx, err := simple.StoreDifficulty(&auth)
Require(t, err)
_, err = EnsureTxSucceeded(ctx, client, tx)
Require(t, err)
difficulty, err := simple.GetBlockDifficulty(&bind.CallOpts{})
Require(t, err)
if !arbmath.BigEquals(difficulty, common.Big1) {
Fatal(t, "Expected difficulty to be 1 but got:", difficulty)
}
}

func TestDifficultyForArbOSTen(t *testing.T) {
amsanghi marked this conversation as resolved.
Show resolved Hide resolved
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

chainConfig := params.ArbitrumDevTestChainConfig()
chainConfig.ArbitrumChainParams.InitialArbOSVersion = 10
l2info, node, client := CreateTestL2WithConfig(t, ctx, nil, arbnode.ConfigDefaultL2Test(), nil, true, chainConfig)
defer node.StopAndWait()

auth := l2info.GetDefaultTransactOpts("Owner", ctx)

// deploy a test contract
_, _, simple, err := mocksgen.DeploySimple(&auth, client)
Require(t, err, "could not deploy contract")

tx, err := simple.StoreDifficulty(&auth)
Require(t, err)
_, err = EnsureTxSucceeded(ctx, client, tx)
Require(t, err)
difficulty, err := simple.GetBlockDifficulty(&bind.CallOpts{})
Require(t, err)
if !arbmath.BigEquals(difficulty, common.Big1) {
Fatal(t, "Expected difficulty to be 1 but got:", difficulty)
}
}

func TestComponentEstimate(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
2 changes: 1 addition & 1 deletion system_tests/infra_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestInfraFee(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

l2info, node, client := CreateTestL2WithConfig(t, ctx, nil, nil, nil, true)
l2info, node, client := CreateTestL2WithConfig(t, ctx, nil, nil, nil, true, nil)
defer node.StopAndWait()

l2info.GenerateAccount("User2")
Expand Down
2 changes: 1 addition & 1 deletion system_tests/initialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestInitContract(t *testing.T) {
l2info.ArbInitData.Accounts = append(l2info.ArbInitData.Accounts, accountInfo)
expectedSums[accountAddress] = sum
}
_, node, client := CreateTestL2WithConfig(t, ctx, l2info, nil, nil, true)
_, node, client := CreateTestL2WithConfig(t, ctx, l2info, nil, nil, true, nil)
defer node.StopAndWait()

for accountAddress, sum := range expectedSums {
Expand Down
2 changes: 1 addition & 1 deletion system_tests/seq_coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestRedisSeqCoordinatorPriorities(t *testing.T) {

createStartNode := func(nodeNum int) {
nodeConfig.SeqCoordinator.MyUrl = nodeNames[nodeNum]
_, node, _ := CreateTestL2WithConfig(t, ctx, l2Info, nodeConfig, nil, false)
_, node, _ := CreateTestL2WithConfig(t, ctx, l2Info, nodeConfig, nil, false, nil)
nodes[nodeNum] = node
}

Expand Down
6 changes: 3 additions & 3 deletions system_tests/seq_nonce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestSequencerParallelNonces(t *testing.T) {

config := gethexec.ConfigDefaultTest()
config.Sequencer.NonceFailureCacheExpiry = time.Minute
l2info, node, client := CreateTestL2WithConfig(t, ctx, nil, nil, config, false)
l2info, node, client := CreateTestL2WithConfig(t, ctx, nil, nil, config, false, nil)
defer node.StopAndWait()

l2info.GenerateAccount("Destination")
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestSequencerNonceTooHigh(t *testing.T) {
defer cancel()

config := gethexec.ConfigDefaultTest()
l2info, node, client := CreateTestL2WithConfig(t, ctx, nil, nil, config, false)
l2info, node, client := CreateTestL2WithConfig(t, ctx, nil, nil, config, false, nil)
defer node.StopAndWait()

l2info.GetInfoWithPrivKey("Owner").Nonce++
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestSequencerNonceTooHighQueueFull(t *testing.T) {
config := gethexec.ConfigDefaultTest()
config.Sequencer.NonceFailureCacheSize = 5
config.Sequencer.NonceFailureCacheExpiry = time.Minute
l2info, node, client := CreateTestL2WithConfig(t, ctx, nil, nil, config, false)
l2info, node, client := CreateTestL2WithConfig(t, ctx, nil, nil, config, false, nil)
defer node.StopAndWait()

count := 15
Expand Down
4 changes: 2 additions & 2 deletions system_tests/seq_reject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ func TestSequencerRejection(t *testing.T) {
seqNodeConfig := arbnode.ConfigDefaultL2Test()
seqNodeConfig.Feed.Output = *newBroadcasterConfigTest()
feedErrChan := make(chan error, 10)
l2info1, nodeA, client1 := CreateTestL2WithConfig(t, ctx, nil, seqNodeConfig, nil, true)
l2info1, nodeA, client1 := CreateTestL2WithConfig(t, ctx, nil, seqNodeConfig, nil, true, nil)
defer nodeA.StopAndWait()

clientNodeConfig := arbnode.ConfigDefaultL2Test()
port := nodeA.BroadcastServer.ListenerAddr().(*net.TCPAddr).Port
clientNodeConfig.Feed.Input = *newBroadcastClientConfigTest(port)

_, nodeB, client2 := CreateTestL2WithConfig(t, ctx, nil, clientNodeConfig, nil, false)
_, nodeB, client2 := CreateTestL2WithConfig(t, ctx, nil, clientNodeConfig, nil, false, nil)
defer nodeB.StopAndWait()

auth := l2info1.GetDefaultTransactOpts("Owner", ctx)
Expand Down
2 changes: 1 addition & 1 deletion system_tests/seq_whitelist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestSequencerWhitelist(t *testing.T) {

config := gethexec.ConfigDefaultTest()
config.Sequencer.SenderWhitelist = GetTestAddressForAccountName(t, "Owner").String() + "," + GetTestAddressForAccountName(t, "User").String()
l2info, l2node, client := CreateTestL2WithConfig(t, ctx, nil, nil, config, true)
l2info, l2node, client := CreateTestL2WithConfig(t, ctx, nil, nil, config, true, nil)
defer l2node.StopAndWait()

l2info.GenerateAccount("User")
Expand Down
8 changes: 4 additions & 4 deletions system_tests/seqfeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ func TestSequencerFeed(t *testing.T) {

seqNodeConfig := arbnode.ConfigDefaultL2Test()
seqNodeConfig.Feed.Output = *newBroadcasterConfigTest()
l2info1, nodeA, client1 := CreateTestL2WithConfig(t, ctx, nil, seqNodeConfig, nil, true)
l2info1, nodeA, client1 := CreateTestL2WithConfig(t, ctx, nil, seqNodeConfig, nil, true, nil)
defer nodeA.StopAndWait()
clientNodeConfig := arbnode.ConfigDefaultL2Test()
port := nodeA.BroadcastServer.ListenerAddr().(*net.TCPAddr).Port
clientNodeConfig.Feed.Input = *newBroadcastClientConfigTest(port)

_, nodeB, client2 := CreateTestL2WithConfig(t, ctx, nil, clientNodeConfig, nil, false)
_, nodeB, client2 := CreateTestL2WithConfig(t, ctx, nil, clientNodeConfig, nil, false, nil)
defer nodeB.StopAndWait()

l2info1.GenerateAccount("User2")
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestRelayedSequencerFeed(t *testing.T) {

seqNodeConfig := arbnode.ConfigDefaultL2Test()
seqNodeConfig.Feed.Output = *newBroadcasterConfigTest()
l2info1, nodeA, client1 := CreateTestL2WithConfig(t, ctx, nil, seqNodeConfig, nil, true)
l2info1, nodeA, client1 := CreateTestL2WithConfig(t, ctx, nil, seqNodeConfig, nil, true, nil)
defer nodeA.StopAndWait()

bigChainId, err := client1.ChainID(ctx)
Expand All @@ -102,7 +102,7 @@ func TestRelayedSequencerFeed(t *testing.T) {
clientNodeConfig := arbnode.ConfigDefaultL2Test()
port = currentRelay.GetListenerAddr().(*net.TCPAddr).Port
clientNodeConfig.Feed.Input = *newBroadcastClientConfigTest(port)
_, nodeC, client3 := CreateTestL2WithConfig(t, ctx, nil, clientNodeConfig, nil, false)
_, nodeC, client3 := CreateTestL2WithConfig(t, ctx, nil, clientNodeConfig, nil, false, nil)
defer nodeC.StopAndWait()
StartWatchChanErr(t, ctx, feedErrChan, nodeC)

Expand Down
Loading