Skip to content

Commit

Permalink
onchain-signer: Use wrapped signer in tests too
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed Jan 6, 2025
1 parent 9e2a32c commit c7989bf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/onchain-signer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 31 additions & 9 deletions examples/onchain-signer/test/CommentBox.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,16 +37,19 @@ 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,
]);

const prevCommentCount = await commentBox.commentCount();
let tx: string;
if (plain) {
if (plainProxy) {
tx = await gasless.makeProxyTxPlain(
await commentBox.getAddress(),
innercall,
Expand All @@ -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);
Expand All @@ -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);
});
});

0 comments on commit c7989bf

Please sign in to comment.