-
Notifications
You must be signed in to change notification settings - Fork 435
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
Add test for ArbitrumContractTx type transactions #1731
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d3cdb0c
tmp
anodar a47d2ba
Add test for ArbitrumContractTx transaction type
anodar 79ee0ad
Revert number of messages in waitForL1DelayBlocks
anodar 577715e
Don't run contract tx test in parallel
anodar 2836848
Merge branch 'master' into test-cases-contractTxType
anodar a1352f7
Merge branch 'master' into test-cases-contractTxType
anodar b97d2c9
Merge branch 'master' into test-cases-contractTxType
anodar aa1c4c8
Merge branch 'master' into test-cases-contractTxType
anodar 522eb88
Use lookupL2Hash instead of looking up by tx hash
anodar 87563a0
Merge branch 'master' into test-cases-contractTxType
anodar ca690bf
drop from error message since it doesn't just refer to retryables
anodar f5966b5
Merge branch 'test-cases-contractTxType' of github.com:OffchainLabs/n…
anodar 95ad8fd
Merge branch 'master' into test-cases-contractTxType
anodar e29317c
Merge branch 'master' into test-cases-contractTxType
anodar 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 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 |
---|---|---|
|
@@ -52,30 +52,38 @@ func retryableSetup(t *testing.T) ( | |
delayedBridge, err := arbnode.NewDelayedBridge(l1client, l1info.GetAddress("Bridge"), 0) | ||
Require(t, err) | ||
|
||
lookupSubmitRetryableL2TxHash := func(l1Receipt *types.Receipt) common.Hash { | ||
lookupL2Hash := func(l1Receipt *types.Receipt) common.Hash { | ||
messages, err := delayedBridge.LookupMessagesInRange(ctx, l1Receipt.BlockNumber, l1Receipt.BlockNumber, nil) | ||
Require(t, err) | ||
if len(messages) == 0 { | ||
Fatal(t, "didn't find message for retryable submission") | ||
} | ||
var submissionTxs []*types.Transaction | ||
msgTypes := map[uint8]bool{ | ||
arbostypes.L1MessageType_SubmitRetryable: true, | ||
arbostypes.L1MessageType_EthDeposit: true, | ||
arbostypes.L1MessageType_L2Message: true, | ||
} | ||
txTypes := map[uint8]bool{ | ||
types.ArbitrumSubmitRetryableTxType: true, | ||
types.ArbitrumDepositTxType: true, | ||
types.ArbitrumContractTxType: true, | ||
} | ||
for _, message := range messages { | ||
k := message.Message.Header.Kind | ||
if k != arbostypes.L1MessageType_SubmitRetryable && k != arbostypes.L1MessageType_EthDeposit { | ||
if !msgTypes[message.Message.Header.Kind] { | ||
continue | ||
} | ||
txs, err := arbos.ParseL2Transactions(message.Message, params.ArbitrumDevTestChainConfig().ChainID, nil) | ||
Require(t, err) | ||
for _, tx := range txs { | ||
if tx.Type() == types.ArbitrumSubmitRetryableTxType || tx.Type() == types.ArbitrumDepositTxType { | ||
if txTypes[tx.Type()] { | ||
submissionTxs = append(submissionTxs, tx) | ||
} | ||
} | ||
} | ||
if len(submissionTxs) != 1 { | ||
Fatal(t, "expected 1 tx from retryable submission, found", len(submissionTxs)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be changed to not just reference retryables now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
|
||
return submissionTxs[0].Hash() | ||
} | ||
|
||
|
@@ -101,7 +109,7 @@ func retryableSetup(t *testing.T) ( | |
l2node.StopAndWait() | ||
requireClose(t, l1stack) | ||
} | ||
return l2info, l1info, l2client, l1client, delayedInbox, lookupSubmitRetryableL2TxHash, ctx, teardown | ||
return l2info, l1info, l2client, l1client, delayedInbox, lookupL2Hash, ctx, teardown | ||
} | ||
|
||
func TestRetryableNoExist(t *testing.T) { | ||
|
@@ -445,6 +453,61 @@ func TestDepositETH(t *testing.T) { | |
} | ||
} | ||
|
||
func TestArbitrumContractTx(t *testing.T) { | ||
l2Info, l1Info, l2Client, l1Client, delayedInbox, lookupL2Hash, ctx, teardown := retryableSetup(t) | ||
defer teardown() | ||
faucetL2Addr := util.RemapL1Address(l1Info.GetAddress("Faucet")) | ||
TransferBalanceTo(t, "Faucet", faucetL2Addr, big.NewInt(1e18), l2Info, l2Client, ctx) | ||
|
||
l2TxOpts := l2Info.GetDefaultTransactOpts("Faucet", ctx) | ||
l2ContractAddr, _ := deploySimple(t, ctx, l2TxOpts, l2Client) | ||
l2ContractABI, err := abi.JSON(strings.NewReader(mocksgen.SimpleABI)) | ||
if err != nil { | ||
t.Fatalf("Error parsing contract ABI: %v", err) | ||
} | ||
data, err := l2ContractABI.Pack("checkCalls", true, true, false, false, false, false) | ||
if err != nil { | ||
t.Fatalf("Error packing method's call data: %v", err) | ||
} | ||
unsignedTx := types.NewTx(&types.ArbitrumContractTx{ | ||
ChainId: l2Info.Signer.ChainID(), | ||
From: faucetL2Addr, | ||
GasFeeCap: l2Info.GasPrice.Mul(l2Info.GasPrice, big.NewInt(2)), | ||
Gas: 1e6, | ||
To: &l2ContractAddr, | ||
Value: common.Big0, | ||
Data: data, | ||
}) | ||
txOpts := l1Info.GetDefaultTransactOpts("Faucet", ctx) | ||
l1tx, err := delayedInbox.SendContractTransaction( | ||
&txOpts, | ||
arbmath.UintToBig(unsignedTx.Gas()), | ||
unsignedTx.GasFeeCap(), | ||
*unsignedTx.To(), | ||
unsignedTx.Value(), | ||
unsignedTx.Data(), | ||
) | ||
if err != nil { | ||
t.Fatalf("Error sending unsigned transaction: %v", err) | ||
} | ||
receipt, err := EnsureTxSucceeded(ctx, l1Client, l1tx) | ||
if err != nil { | ||
t.Fatalf("EnsureTxSucceeded(%v) unexpected error: %v", l1tx.Hash(), err) | ||
} | ||
if receipt.Status != types.ReceiptStatusSuccessful { | ||
t.Errorf("L1 transaction: %v has failed", l1tx.Hash()) | ||
} | ||
waitForL1DelayBlocks(t, ctx, l1Client, l1Info) | ||
txHash := lookupL2Hash(receipt) | ||
receipt, err = WaitForTx(ctx, l2Client, txHash, time.Second*5) | ||
if err != nil { | ||
t.Fatalf("EnsureTxSucceeded(%v) unexpected error: %v", unsignedTx.Hash(), err) | ||
} | ||
if receipt.Status != types.ReceiptStatusSuccessful { | ||
t.Errorf("L2 transaction: %v has failed", receipt.TxHash) | ||
} | ||
} | ||
|
||
func TestL1FundedUnsignedTransaction(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be changed to not just reference retryables now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.