forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 14
Add Celo CIP-64 acceptance test (sysgo) #440
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
Draft
palango
wants to merge
18
commits into
celo-rebase-17
Choose a base branch
from
palango/celo-cip64-acceptance-test
base: celo-rebase-17
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
55a7624
op-deployer,contracts: Add deployCeloContracts flag to L2Genesis
palango e3fad4a
op-devstack,op-e2e: Add sysgo.WithCelo() option
palango e37ba5b
op-deployer,op-e2e,contracts: Land CIP-64 txs on sysgo Celo chains
palango 4b29439
op-acceptance-tests: Add Celo CIP-64 fee-currency test
palango f1f9c6f
contracts: Initialize SortedOracles in setCeloPredeploys
palango fc01165
op-devstack: Move Celo miner config out of generic geth.InitL2
palango a0c19f2
contracts,op-deployer: Make zero-scalar guard conditional on deployCe…
palango fec5c02
op-core,op-devstack,op-acceptance-tests: Single source of truth for F…
palango 674d72c
op-deployer: Use predeploys constants in TestApplyDeployCeloContracts
palango fbc2ab1
op-deployer: Rename celoOrDefault to celoOrDefaultScalar for consistency
palango b137861
contracts: Use vm.prank for single-call pranks in setCeloPredeploys
palango 5eeab6b
op-devstack,op-e2e: Drop unused bool param from WithDeployCeloContracts
palango df36775
contracts,op-chain-ops: Update remaining L2GenesisInput / DeployOPCha…
palango 5ffb3fb
contracts: Move AddressSortedLinkedListWithMedian library link to fou…
palango 021c193
op-acceptance-tests: Make ensureCeloFeeCurrencyOrSkip actually skip n…
palango 6840eb5
contracts: Move AddressSortedLinkedListWithMedian library link to for…
palango 999df5f
contracts: Update test struct literals for new deployCeloContracts field
palango ae871db
ci: Add dedicated memory-celo acceptance-test job
palango File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,84 @@ | ||
| package celo | ||
|
|
||
| import ( | ||
| "context" | ||
| "math/big" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/ethereum/go-ethereum/core/types" | ||
| "github.com/ethereum/go-ethereum/crypto" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-core/predeploys" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/devtest" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/presets" | ||
| ) | ||
|
|
||
| // TestCIP64_PayGasInTestFeeCurrency sends a CeloDynamicFeeTxV2 (CIP-64) with | ||
| // FeeCurrency set to the registered test fee currency. devAccounts[0] is the | ||
| // foundry test mnemonic account that L2Genesis pre-funds with 100k TEST and | ||
| // zero native CELO; the only way the tx can be paid for is via op-geth's | ||
| // fee-currency machinery. | ||
| func TestCIP64_PayGasInTestFeeCurrency(gt *testing.T) { | ||
| t := devtest.SerialT(gt) | ||
| sys := presets.NewMinimal(t) | ||
| ensureCeloFeeCurrencyOrSkip(t, sys) | ||
|
|
||
| priv, err := crypto.HexToECDSA(foundryDevAccount0PrivKeyHex) | ||
| t.Require().NoError(err, "parse foundry dev priv key") | ||
| sender := crypto.PubkeyToAddress(priv.PublicKey) | ||
|
|
||
| l2 := sys.L2EL.Escape().L2EthClient() | ||
| chainID := sys.L2Chain.ChainID().ToBig() | ||
| recipient := sys.Wallet.NewEOA(sys.L2EL).Address() | ||
|
|
||
| ctx, cancel := context.WithTimeout(t.Ctx(), 60*time.Second) | ||
| defer cancel() | ||
|
|
||
| nativeBefore, err := l2.BalanceAt(ctx, sender, nil) | ||
| t.Require().NoError(err, "get native balance") | ||
| testBefore := erc20BalanceOf(t, sys, predeploys.TestFeeCurrencyAddr, sender) | ||
| t.Require().Truef(testBefore.Sign() > 0, "sender must have a positive TEST balance, got %s", testBefore) | ||
|
|
||
| nonce, err := l2.PendingNonceAt(ctx, sender) | ||
| t.Require().NoError(err, "get nonce") | ||
|
|
||
| tx := types.NewTx(&types.CeloDynamicFeeTxV2{ | ||
| ChainID: chainID, | ||
| Nonce: nonce, | ||
| GasTipCap: big.NewInt(1_000_000_000), // 1 gwei | ||
| GasFeeCap: big.NewInt(10_000_000_000), // 10 gwei | ||
| Gas: 200_000, | ||
| To: &recipient, | ||
| Value: big.NewInt(0), | ||
| FeeCurrency: &predeploys.TestFeeCurrencyAddr, | ||
| }) | ||
| signed, err := types.SignTx(tx, types.LatestSignerForChainID(chainID), priv) | ||
| t.Require().NoError(err, "sign CIP-64 tx") | ||
| t.Require().NoError(l2.SendTransaction(ctx, signed), "send CIP-64 tx") | ||
|
|
||
| var receipt *types.Receipt | ||
| t.Require().Eventually(func() bool { | ||
| r, err := l2.TransactionReceipt(ctx, signed.Hash()) | ||
| if err != nil { | ||
| return false | ||
| } | ||
| receipt = r | ||
| return true | ||
| }, sys.L2EL.Escape().TransactionTimeout(), time.Second, "tx receipt") | ||
|
|
||
| t.Require().Equal(uint64(1), receipt.Status, "CIP-64 tx must succeed") | ||
|
|
||
| nativeAfter, err := l2.BalanceAt(ctx, sender, nil) | ||
| t.Require().NoError(err, "get native balance after") | ||
| testAfter := erc20BalanceOf(t, sys, predeploys.TestFeeCurrencyAddr, sender) | ||
|
|
||
| // Native balance must not change: gas was paid in TEST, no value transferred. | ||
| t.Require().Equal(0, nativeBefore.Cmp(nativeAfter), | ||
| "native balance changed: before=%s after=%s", nativeBefore, nativeAfter) | ||
|
|
||
| // TEST balance must drop — the fee-currency machinery debited gas + intrinsic-gas | ||
| // surcharge in TEST tokens. | ||
| t.Require().Truef(testAfter.Cmp(testBefore) < 0, | ||
| "TEST balance must drop, got before=%s after=%s", testBefore, testAfter) | ||
| } |
This file contains hidden or 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,64 @@ | ||
| package celo | ||
|
|
||
| import ( | ||
| "context" | ||
| "math/big" | ||
| "time" | ||
|
|
||
| "github.com/ethereum/go-ethereum" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/rpc" | ||
| "github.com/lmittmann/w3" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-core/predeploys" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/devtest" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/presets" | ||
| ) | ||
|
|
||
| // Foundry "test test test test test test test test test test test junk" mnemonic, | ||
| // path m/44'/60'/0'/0/0 — same address that L2Genesis.s.sol pre-funds with 100k TEST. | ||
| const foundryDevAccount0PrivKeyHex = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" | ||
|
|
||
| // ensureCeloFeeCurrencyOrSkip checks that the FeeCurrencyDirectory predeploy is in | ||
| // place and that the test fee currency is registered. Skips the test otherwise so | ||
| // the gate can be run against environments without the Celo predeploys. | ||
| func ensureCeloFeeCurrencyOrSkip(t devtest.T, sys *presets.Minimal) { | ||
| l2 := sys.L2EL.Escape().L2EthClient() | ||
|
|
||
| ctx, cancel := context.WithTimeout(t.Ctx(), 20*time.Second) | ||
| defer cancel() | ||
|
|
||
| // Probe the FeeCurrencyDirectory by calling getCurrencyConfig(testFeeCurrency). | ||
| // On a non-Celo devnet the call has no code to execute and reverts; on a Celo | ||
| // devnet without the test currency registered, the directory itself reverts | ||
| // with "currency not registered". Both cases skip. | ||
| getCurrencyConfig := w3.MustNewFunc( | ||
| "getCurrencyConfig(address)", | ||
| "(address oracle, uint256 intrinsicGas)", | ||
| ) | ||
| data, err := getCurrencyConfig.EncodeArgs(predeploys.TestFeeCurrencyAddr) | ||
| t.Require().NoError(err, "encode getCurrencyConfig") | ||
|
|
||
| if _, err := l2.Call(ctx, ethereum.CallMsg{To: &predeploys.FeeCurrencyDirectoryAddr, Data: data}, rpc.LatestBlockNumber); err != nil { | ||
| t.Skip("test fee currency not registered with FeeCurrencyDirectory: " + err.Error()) | ||
| } | ||
| } | ||
|
|
||
| // erc20BalanceOf reads the ERC-20 balance of `account` for the token at `token`. | ||
| func erc20BalanceOf(t devtest.T, sys *presets.Minimal, token, account common.Address) *big.Int { | ||
| l2 := sys.L2EL.Escape().L2EthClient() | ||
|
|
||
| ctx, cancel := context.WithTimeout(t.Ctx(), 20*time.Second) | ||
| defer cancel() | ||
|
|
||
| balanceOf := w3.MustNewFunc("balanceOf(address)", "uint256") | ||
| data, err := balanceOf.EncodeArgs(account) | ||
| t.Require().NoError(err, "encode balanceOf") | ||
|
|
||
| out, err := l2.Call(ctx, ethereum.CallMsg{To: &token, Data: data}, rpc.LatestBlockNumber) | ||
| t.Require().NoError(err, "call balanceOf") | ||
|
|
||
| var bal *big.Int | ||
| t.Require().NoError(balanceOf.DecodeReturns(out, &bal), "decode balanceOf") | ||
| return bal | ||
| } | ||
This file contains hidden or 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,18 @@ | ||
| package celo | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-devstack/presets" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/stack" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/sysgo" | ||
| ) | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| presets.DoMain(m, | ||
| presets.WithMinimal(), | ||
| stack.MakeCommon(sysgo.WithDeployerOptions( | ||
| sysgo.WithCelo(), | ||
| )), | ||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.