-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix e2e tests on alfajores #320
base: celo11
Are you sure you want to change the base?
Changes from 3 commits
9bf00f7
232effe
e527ae6
b301128
45b24c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,12 @@ import { | |
} from "viem"; | ||
import { publicClient, walletClient } from "./viem_setup.mjs" | ||
|
||
// Returns the base fee per gas for the current block multiplied by 2 to account for any increase in the subsequent block. | ||
async function getGasFees(publicClient, tip, feeCurrency) { | ||
// Returns the base fee per gas for the current block in the given fee currency. | ||
async function getGasFees(publicClient, feeCurrency, tip) { | ||
const rate = await getRate(feeCurrency); | ||
const b = await publicClient.getBlock(); | ||
const tipInFeeCurrency = rate.toFeeCurrency(tip); | ||
return [rate.toFeeCurrency(b.baseFeePerGas) + tipInFeeCurrency, tipInFeeCurrency]; | ||
const convertedTip = rate.toFeeCurrency(tip); | ||
return [ rate.toFeeCurrency(b.baseFeePerGas)+convertedTip, convertedTip]; | ||
} | ||
|
||
const testNonceBump = async ( | ||
|
@@ -99,14 +99,21 @@ describe("viem send tx", () => { | |
}).timeout(10_000); | ||
|
||
it("send fee currency tx with explicit gas fields and check receipt", async () => { | ||
const [maxFeePerGas, tip] = await getGasFees(publicClient, 2n, process.env.FEE_CURRENCY); | ||
// Our execution nodes are configured by default with a min tip of 1 wei in | ||
// celo, which when converted to fee currency could be a higher value, so | ||
// we need to ensure we use the min tip in fee currency when submitting a | ||
// tx with fee a fee currency. | ||
const [maxFeePerGasInFeeCurrency, tipInFeeCurrency] = await getGasFees(publicClient, process.env.FEE_CURRENCY, 1n); | ||
|
||
const request = await walletClient.prepareTransactionRequest({ | ||
to: "0x00000000000000000000000000000000DeaDBeef", | ||
value: 2, | ||
gas: 171000, | ||
feeCurrency: process.env.FEE_CURRENCY, | ||
maxFeePerGas: maxFeePerGas, | ||
maxPriorityFeePerGas: tip, | ||
// We multiply the maxFeePerGas by 10 here to account for fluctuations in | ||
// the base fee, since these tests can be run against a live network. | ||
maxFeePerGas: maxFeePerGasInFeeCurrency*10n, | ||
maxPriorityFeePerGas: tipInFeeCurrency, | ||
}); | ||
const signature = await walletClient.signTransaction(request); | ||
const hash = await walletClient.sendRawTransaction({ | ||
|
@@ -195,15 +202,15 @@ describe("viem send tx", () => { | |
// more liable to result in a failure. | ||
it("send overlapping nonce tx in different currencies", async () => { | ||
// Note the threshold for a price bump to be accepted is 10%, i.e >= oldPrice * 1.1 | ||
const priceBump = 1.1; // minimum bump percentage to replace a transaction | ||
const priceBump = 1.11; // minimum bump percentage to replace a transaction | ||
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. It's also likely that the precision loss comes from the test's I'd rather try to make the tests calculation more accurate before tweaking the values. |
||
const priceNearBump = 1.09; // slightly lower percentage than the price bump | ||
|
||
const rate = await getRate(process.env.FEE_CURRENCY); | ||
// Native to FEE_CURRENCY | ||
const nativeCap = 30_000_000_000; | ||
const bumpCurrencyCap = rate.toFeeCurrency(BigInt(Math.round(nativeCap * priceBump))); | ||
const bumpCurrencyCap = rate.toFeeCurrency(BigInt(Math.ceil(nativeCap * priceBump))); | ||
const failToBumpCurrencyCap = rate.toFeeCurrency(BigInt( | ||
Math.round(nativeCap * priceNearBump) | ||
Math.floor(nativeCap * priceNearBump) | ||
)); | ||
const tokenCurrency = process.env.FEE_CURRENCY; | ||
const nativeCurrency = null; | ||
|
@@ -224,9 +231,9 @@ describe("viem send tx", () => { | |
|
||
// FEE_CURRENCY to Native | ||
const currencyCap = 60_000_000_000; | ||
const bumpNativeCap = rate.toNative(BigInt(Math.round(currencyCap * priceBump))); | ||
const bumpNativeCap = rate.toNative(BigInt(Math.ceil(currencyCap * priceBump))); | ||
const failToBumpNativeCap = rate.toNative(BigInt( | ||
Math.round(currencyCap * priceNearBump) | ||
Math.floor(currencyCap * priceNearBump) | ||
)); | ||
await testNonceBump( | ||
currencyCap, | ||
|
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.
The changes in the function are not really necessary anymore :)