(tc: {
functionName: 'staticCall' | 'delegateCall' | 'execute' | 'callCode'
fn: 'mint' | 'transfer'
})
| 1671 | }) |
| 1672 | |
| 1673 | const testCallType = async (tc: { |
| 1674 | functionName: 'staticCall' | 'delegateCall' | 'execute' | 'callCode' |
| 1675 | fn: 'mint' | 'transfer' |
| 1676 | }) => { |
| 1677 | const { client, usdc, receiver, totalSupply, sender } = await clients() |
| 1678 | const helper = CallHelper.attach(sender, helperAddress) |
| 1679 | const amount = USDC.parseUnits('0.000001') |
| 1680 | |
| 1681 | const balances = await balancesSnapshot(client, { |
| 1682 | sender, |
| 1683 | helper, |
| 1684 | totalSupply, |
| 1685 | receiverUSDC: () => usdc.balanceOf([receiver.account.address]), |
| 1686 | }) |
| 1687 | |
| 1688 | const receipt = await sender |
| 1689 | .sendTransaction({ |
| 1690 | to: helper.address, |
| 1691 | data: CallHelper.encodeNested({ |
| 1692 | fn: tc.functionName, |
| 1693 | target: USDC.address, |
| 1694 | data: encodeFunctionData({ abi: USDC.abi, functionName: tc.fn, args: [receiver.account.address, amount] }), |
| 1695 | }), |
| 1696 | }) |
| 1697 | .then(ReceiptVerifier.waitSuccess) |
| 1698 | |
| 1699 | const verifySuccess = async () => { |
| 1700 | if (tc.fn === 'mint') { |
| 1701 | receipt.verifyEvents((ev) => { |
| 1702 | ev.expectNativeMint({ recipient: receiver, amount: USDC.toNative(amount) }) |
| 1703 | .expectUSDCMint({ minter: helper, to: receiver, amount: amount }) |
| 1704 | .expectUSDCTransfer({ from: zeroAddress, to: receiver, value: amount }) |
| 1705 | .expectExecutionResult({ helper, success: true, result: toBytes32(1n) }) |
| 1706 | .expectAllEventsMatched() |
| 1707 | }) |
| 1708 | await balances |
| 1709 | .decrease({ sender: receipt.totalFee() }) |
| 1710 | .increase({ receiverUSDC: amount, totalSupply: USDC.toNative(amount) }) |
| 1711 | .verify() |
| 1712 | } else { |
| 1713 | receipt.verifyEvents((ev) => { |
| 1714 | ev.expectNativeTransfer({ from: helper, to: receiver, amount: USDC.toNative(amount) }) |
| 1715 | .expectUSDCTransfer({ from: helper, to: receiver, value: amount }) |
| 1716 | .expectExecutionResult({ helper, success: true, result: toBytes32(1n) }) |
| 1717 | .expectAllEventsMatched() |
| 1718 | }) |
| 1719 | await balances |
| 1720 | .decrease({ sender: receipt.totalFee(), helper: USDC.toNative(amount) }) |
| 1721 | .increase({ receiverUSDC: amount }) |
| 1722 | .verify() |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | return { receipt, balances, helper, amount, sender, receiver, verifySuccess } |
| 1727 | } |
| 1728 | |
| 1729 | it('staticCall USDC.transfer', async () => { |
| 1730 | const { receipt, balances, helper } = await testCallType({ functionName: 'staticCall', fn: 'transfer' }) |
no test coverage detected