Skip to content

Commit

Permalink
Address gas estimate too low in tests when multiple test NFT are bein…
Browse files Browse the repository at this point in the history
…g minted in one block by incrementing the nonce properly (#148)

…

---------

Signed-off-by: Brian Meek <[email protected]>
  • Loading branch information
brianathere authored Jun 12, 2024
1 parent d6e8697 commit f226d75
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions packages/web3/src/TestGatingNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { foundry } from 'viem/chains'

import MockERC721a from './MockERC721A'

import { keccak256 } from 'viem/utils'
import { keccak256, parseEther } from 'viem/utils'
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'

import { dlogger } from '@river-build/dlog'

const logger = dlogger('csb:TestGatingNFT')
Expand Down Expand Up @@ -94,19 +96,25 @@ export async function getContractAddress(nftName: string): Promise<`0x${string}`
if (!nftContracts.has(nftName)) {
while (retryCount++ < 5) {
try {
const privateKey = generatePrivateKey()
const throwawayAccount = privateKeyToAccount(privateKey)
const client = createTestClient({
chain: foundry,
mode: 'anvil',
transport: http(),
account: throwawayAccount,
})
.extend(publicActions)
.extend(walletActions)

const account = (await client.getAddresses())[0]
await client.setBalance({
address: throwawayAccount.address,
value: parseEther('1'),
})

const hash = await client.deployContract({
abi: MockERC721a.abi,
account,
account: throwawayAccount,
bytecode: MockERC721a.bytecode.object,
})

Expand Down Expand Up @@ -166,27 +174,34 @@ export async function getTestGatingNFTContractAddress(): Promise<`0x${string}`>
}

export async function publicMint(nftName: string, toAddress: `0x${string}`) {
const privateKey = generatePrivateKey()
const throwawayAccount = privateKeyToAccount(privateKey)
const client = createTestClient({
chain: foundry,
mode: 'anvil',
transport: http(),
account: throwawayAccount,
})
.extend(publicActions)
.extend(walletActions)

await client.setBalance({
address: throwawayAccount.address,
value: parseEther('1'),
})

const contractAddress = await getContractAddress(nftName)

logger.log('minting', contractAddress, toAddress)

const account = (await client.getAddresses())[0]

const nftReceipt = await client.writeContract({
address: contractAddress,
abi: MockERC721a.abi,
functionName: 'mint',
args: [toAddress, 1n],
account,
account: throwawayAccount,
})
logger.log('minted', nftReceipt)

const receipt = await client.waitForTransactionReceipt({ hash: nftReceipt })
expect(receipt.status).toBe('success')
Expand Down

0 comments on commit f226d75

Please sign in to comment.