diff --git a/examples/onchain-signer/package.json b/examples/onchain-signer/package.json index c2a53a4e..6a65a43b 100644 --- a/examples/onchain-signer/package.json +++ b/examples/onchain-signer/package.json @@ -25,6 +25,7 @@ "@nomicfoundation/hardhat-verify": "^2.0.2", "@oasisprotocol/sapphire-contracts": "workspace:^", "@oasisprotocol/sapphire-hardhat": "workspace:^", + "@oasisprotocol/sapphire-paratime": "workspace:^", "@typechain/ethers-v6": "^0.5.1", "@typechain/hardhat": "^9.1.0", "@types/mocha": "^9.1.1", diff --git a/examples/onchain-signer/test/CommentBox.ts b/examples/onchain-signer/test/CommentBox.ts index d017283a..f464c1b2 100644 --- a/examples/onchain-signer/test/CommentBox.ts +++ b/examples/onchain-signer/test/CommentBox.ts @@ -1,9 +1,12 @@ import { expect } from 'chai'; -import { Context } from 'mocha'; import { ethers } from 'hardhat'; import { parseEther, Wallet } from 'ethers'; import { CommentBox, Gasless } from '../typechain-types'; import { EthereumKeypairStruct } from '../typechain-types/contracts/Gasless'; +import { + isCalldataEnveloped, + wrapEthereumProvider +} from "@oasisprotocol/sapphire-paratime"; describe('CommentBox', function () { let commentBox: CommentBox; @@ -34,8 +37,11 @@ describe('CommentBox', function () { console.log(' . gasless pubkey', wallet.address); }); - async function commentGasless(comment: string, plain: boolean) { - const provider = ethers.provider; + // Request and send a gasless transaction. Set up sapphire-localnet image to + // run this test: + // docker run -it -p8544-8548:8544-8548 ghcr.io/oasisprotocol/sapphire-localnet + async function commentGasless(comment: string, plainProxy: boolean, unwrappedProvider: boolean) { + const provider = unwrappedProvider ? ethers.provider : wrapEthereumProvider(ethers.provider); const innercall = commentBox.interface.encodeFunctionData('comment', [ comment, @@ -43,7 +49,7 @@ describe('CommentBox', function () { const prevCommentCount = await commentBox.commentCount(); let tx: string; - if (plain) { + if (plainProxy) { tx = await gasless.makeProxyTxPlain( await commentBox.getAddress(), innercall, @@ -52,8 +58,8 @@ describe('CommentBox', function () { tx = await gasless.makeProxyTx(await commentBox.getAddress(), innercall); } - // TODO: https://github.com/oasisprotocol/sapphire-paratime/issues/179 const response = await provider.broadcastTransaction(tx); + expect(isCalldataEnveloped(response.data)).eq(!plainProxy); await response.wait(); const receipt = await provider.getTransactionReceipt(response.hash); @@ -71,23 +77,39 @@ describe('CommentBox', function () { expect(await commentBox.commentCount()).eq(prevCommentCount + BigInt(1)); }); - it('Should comment gasless (encrypted)', async function () { + it('Should comment gasless (encrypted proxy tx, wrapped client)', async function () { + if ((await ethers.provider.getNetwork()).chainId == BigInt(1337)) { + this.skip(); + } + + await commentGasless('Hello, c10l world', false, false); + }); + + it('Should comment gasless (encrypted proxy tx, unwrapped client)', async function () { + if ((await ethers.provider.getNetwork()).chainId == BigInt(1337)) { + this.skip(); + } + + await commentGasless('Hello, c10l world', false, true); + }); + + it('Should comment gasless (plain proxy tx, wrapped client)', async function () { // Set up sapphire-localnet image to run this test: // docker run -it -p8544-8548:8544-8548 ghcr.io/oasisprotocol/sapphire-localnet if ((await ethers.provider.getNetwork()).chainId == BigInt(1337)) { this.skip(); } - await commentGasless('Hello, c10l world', false); + await commentGasless('Hello, plain world', true, false); }); - it('Should comment gasless (plain)', async function () { + it('Should comment gasless (plain proxy tx, unwrapped client)', async function () { // Set up sapphire-localnet image to run this test: // docker run -it -p8544-8548:8544-8548 ghcr.io/oasisprotocol/sapphire-localnet if ((await ethers.provider.getNetwork()).chainId == BigInt(1337)) { this.skip(); } - await commentGasless('Hello, plain world', true); + await commentGasless('Hello, plain world', true, true); }); });