forked from ethereum-optimism/op-geth
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since some e2e tests now produce invalidated transactions that remain in the txpool until replaced, the `send_tx.mjs` script required some changes to replace the sent CIP64 transaction. It will get replaced after 2 blocks of producing no receipt. Those changes also required the geth-node to run in periodic --dev mode instead of the on-demand "produce-block-per-transaction" mode, which will unfortunately make the tests run longer than before. The bash scripts and tests itself have also been refactored to make code segments more reusable with the help of functions.
- Loading branch information
Showing
10 changed files
with
255 additions
and
66 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,60 @@ | ||
#!/bin/bash | ||
#shellcheck disable=SC2034,SC2155,SC2086 | ||
set -xeo pipefail | ||
|
||
function txpool_content() { | ||
cast rpc txpool_content | jq | ||
} | ||
|
||
# args: | ||
# $1: failOnDebit (bool): | ||
# if true, this will make the DebugFeeCurrenc.DebitFees() call fail with a revert | ||
# $2: failOnCredit (bool) | ||
# if true, this will make the DebugFeeCurrenc.CreditFees() call fail with a revert | ||
# $3: highGasOnCredit (bool) | ||
# if true, this will make the DebugFeeCurrenc.CreditFees() call use | ||
# a high amount of gas | ||
# returns: | ||
# deployed fee-currency address | ||
function deploy_fee_currency() { | ||
( | ||
local fee_currency=$( | ||
forge create --root "$SCRIPT_DIR/debug-fee-currency" --contracts "$SCRIPT_DIR/debug-fee-currency" --private-key $ACC_PRIVKEY DebugFeeCurrency.sol:DebugFeeCurrency --constructor-args '100000000000000000000000000' $1 $2 $3 --json | jq .deployedTo -r | ||
) | ||
if [ -z "${fee_currency}" ]; then | ||
exit 1 | ||
fi | ||
cast send --private-key $ACC_PRIVKEY $ORACLE3 'setExchangeRate(address, uint256, uint256)' $fee_currency 2ether 1ether &>/dev/null | ||
cast send --private-key $ACC_PRIVKEY $FEE_CURRENCY_DIRECTORY_ADDR 'setCurrencyConfig(address, address, uint256)' $fee_currency $ORACLE3 60000 &>/dev/null | ||
echo "$fee_currency" | ||
) | ||
} | ||
|
||
# args: | ||
# $1: feeCurrencyAddress (string): | ||
# which fee-currency address to use for the default CIP-64 transaction | ||
function cip_64_tx() { | ||
$SCRIPT_DIR/js-tests/send_tx.mjs "$(cast chain-id)" $ACC_PRIVKEY $1 | ||
} | ||
|
||
# use this function to assert the cip_64_tx return value, by using a pipe like | ||
# `cip_64_tx "$fee-currency" | assert_cip_64_tx true` | ||
# | ||
# args: | ||
# $1: success (string): | ||
# expected success value, "true" for when the cip-64 tx should have succeeded, "false" if not | ||
# $2: error-regex (string): | ||
# expected RPC return-error value regex to grep for, use "null", "" or unset value if no error is assumed. | ||
function assert_cip_64_tx() { | ||
local value | ||
read -r value | ||
local expected_error="$2" | ||
|
||
if [ "$(echo "$value" | jq .success)" != "$1" ]; then | ||
exit 1 | ||
fi | ||
if [ -z "$expected_error" ]; then | ||
expected_error="null" | ||
fi | ||
echo "$value" | jq .error | grep -qE "$expected_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 |
---|---|---|
@@ -1,44 +1,127 @@ | ||
#!/usr/bin/env node | ||
import { | ||
createPublicClient, | ||
createWalletClient, | ||
http, | ||
defineChain, | ||
createWalletClient, | ||
createPublicClient, | ||
http, | ||
defineChain, | ||
TransactionReceiptNotFoundError, | ||
} from "viem"; | ||
import { celoAlfajores } from "viem/chains"; | ||
import { privateKeyToAccount } from "viem/accounts"; | ||
|
||
const [chainId, privateKey, feeCurrency] = process.argv.slice(2); | ||
const devChain = defineChain({ | ||
...celoAlfajores, | ||
id: parseInt(chainId, 10), | ||
name: "local dev chain", | ||
network: "dev", | ||
rpcUrls: { | ||
default: { | ||
http: ["http://127.0.0.1:8545"], | ||
}, | ||
}, | ||
...celoAlfajores, | ||
id: parseInt(chainId, 10), | ||
name: "local dev chain", | ||
network: "dev", | ||
rpcUrls: { | ||
default: { | ||
http: ["http://127.0.0.1:8545"], | ||
}, | ||
}, | ||
}); | ||
|
||
const account = privateKeyToAccount(privateKey); | ||
const walletClient = createWalletClient({ | ||
account, | ||
chain: devChain, | ||
transport: http(), | ||
}); | ||
|
||
const request = await walletClient.prepareTransactionRequest({ | ||
account, | ||
to: "0x00000000000000000000000000000000DeaDBeef", | ||
value: 2, | ||
gas: 90000, | ||
feeCurrency, | ||
maxFeePerGas: 2000000000n, | ||
maxPriorityFeePerGas: 0n, | ||
const publicClient = createPublicClient({ | ||
account, | ||
chain: devChain, | ||
transport: http(), | ||
}); | ||
const signature = await walletClient.signTransaction(request); | ||
const hash = await walletClient.sendRawTransaction({ | ||
serializedTransaction: signature, | ||
const walletClient = createWalletClient({ | ||
account, | ||
chain: devChain, | ||
transport: http(), | ||
}); | ||
console.log(hash); | ||
|
||
async function getTransactionReceiptAfterWait(hash, numBlocks) { | ||
var count = 0; | ||
|
||
const res = new Promise((resolve) => { | ||
resolve(); | ||
}); | ||
const unwatch = publicClient.watchBlockNumber({ | ||
onBlockNumber: () => { | ||
count++; | ||
if (count >= numBlocks) { | ||
res.resolve(); | ||
} | ||
}, | ||
}); | ||
await res; | ||
unwatch(); | ||
try { | ||
return await publicClient.getTransactionReceipt({ hash: hash }); | ||
} catch (e) { | ||
if (e instanceof TransactionReceiptNotFoundError) { | ||
return undefined; | ||
} | ||
throw e; | ||
} | ||
} | ||
|
||
async function replaceTx(tx) { | ||
const request = await walletClient.prepareTransactionRequest({ | ||
account: tx.account, | ||
to: account.address, | ||
value: 0n, | ||
gas: 21000, | ||
nonce: tx.nonce, | ||
maxFeePerGas: tx.maxFeePerGas, | ||
maxPriorityFeePerGas: tx.maxPriorityFeePerGas + 1000n, | ||
}); | ||
const hash = await walletClient.sendRawTransaction({ | ||
serializedTransaction: await walletClient.signTransaction(request), | ||
}); | ||
const receipt = await publicClient.waitForTransactionReceipt({ | ||
hash: hash, | ||
confirmations: 2, | ||
}); | ||
return receipt; | ||
} | ||
|
||
async function main() { | ||
const request = await walletClient.prepareTransactionRequest({ | ||
account, | ||
to: "0x00000000000000000000000000000000DeaDBeef", | ||
value: 2n, | ||
gas: 90000, | ||
feeCurrency, | ||
maxFeePerGas: 2000000000n, | ||
maxPriorityFeePerGas: 0n, | ||
}); | ||
|
||
var hash; | ||
try { | ||
hash = await walletClient.sendRawTransaction({ | ||
serializedTransaction: await walletClient.signTransaction(request), | ||
}); | ||
} catch (e) { | ||
// direct revert | ||
console.log( | ||
JSON.stringify({ | ||
success: false, | ||
error: e, | ||
}), | ||
); | ||
return; | ||
} | ||
|
||
var success = true; | ||
var receipt = await getTransactionReceiptAfterWait(hash, 2); | ||
if (!receipt) { | ||
receipt = await replaceTx(request); | ||
success = false; | ||
} | ||
// print for bash script wrapper return value | ||
console.log( | ||
JSON.stringify({ | ||
success: success, | ||
error: null, | ||
}), | ||
); | ||
|
||
return receipt; | ||
} | ||
await main(); |
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
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
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
Oops, something went wrong.