-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add encryptCallData() to gasless chapter and example #477
Open
matevz
wants to merge
2
commits into
main
Choose a base branch
from
matevz/docs/encryptcalldata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+98
−51
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||||
import { expect } from 'chai'; | ||||||||
import { Context } from 'mocha'; | ||||||||
import { ethers } from 'hardhat'; | ||||||||
import { parseEther, Wallet } from 'ethers'; | ||||||||
import { CommentBox, Gasless } from '../typechain-types'; | ||||||||
|
@@ -33,55 +34,60 @@ describe('CommentBox', function () { | |||||||
console.log(' . gasless pubkey', wallet.address); | ||||||||
}); | ||||||||
|
||||||||
it('Should comment', async function () { | ||||||||
this.timeout(10000); | ||||||||
async function commentGasless(comment: string, plain: boolean) { | ||||||||
const provider = ethers.provider; | ||||||||
|
||||||||
const innercall = commentBox.interface.encodeFunctionData('comment', [ | ||||||||
comment, | ||||||||
]); | ||||||||
|
||||||||
const prevCommentCount = await commentBox.commentCount(); | ||||||||
let tx: string; | ||||||||
if (plain) { | ||||||||
tx = await gasless.makeProxyTxPlain( | ||||||||
await commentBox.getAddress(), | ||||||||
innercall, | ||||||||
); | ||||||||
} else { | ||||||||
tx = await gasless.makeProxyTx(await commentBox.getAddress(), innercall); | ||||||||
} | ||||||||
|
||||||||
const tx = await commentBox.comment('Hello, world!'); | ||||||||
await tx.wait(); | ||||||||
// TODO: https://github.com/oasisprotocol/sapphire-paratime/issues/179 | ||||||||
const response = await provider.broadcastTransaction(tx); | ||||||||
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. calldata encryption could be checked here (requires sapphire-paratime import)
Suggested change
also is the TODO still open? |
||||||||
await response.wait(); | ||||||||
|
||||||||
// Sapphire Mainnet/Testnet: Wait a few moments for nodes to catch up. | ||||||||
const chainId = (await ethers.provider.getNetwork()).chainId; | ||||||||
if (chainId == BigInt(23294) || chainId == BigInt(23295)) { | ||||||||
await new Promise((r) => setTimeout(r, 6_000)); | ||||||||
} | ||||||||
const receipt = await provider.getTransactionReceipt(response.hash); | ||||||||
if (!receipt || receipt.status != 1) throw new Error('tx failed'); | ||||||||
|
||||||||
expect(await commentBox.commentCount()).eq(prevCommentCount + BigInt(1)); | ||||||||
}); | ||||||||
} | ||||||||
|
||||||||
it('Should comment', async function () { | ||||||||
const prevCommentCount = await commentBox.commentCount(); | ||||||||
|
||||||||
it('Should comment gasless', async function () { | ||||||||
this.timeout(10000); | ||||||||
const tx = await commentBox.comment('Hello, world!'); | ||||||||
await tx.wait(); | ||||||||
|
||||||||
const provider = ethers.provider; | ||||||||
expect(await commentBox.commentCount()).eq(prevCommentCount + BigInt(1)); | ||||||||
}); | ||||||||
|
||||||||
// You can set up sapphire-localnet image and run the test like this: | ||||||||
// docker run -it -p8545:8545 -p8546:8546 ghcr.io/oasisprotocol/sapphire-localnet -to 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 | ||||||||
// npx hardhat test --grep proxy --network sapphire-localnet | ||||||||
const chainId = (await provider.getNetwork()).chainId; | ||||||||
if (chainId == BigInt(1337)) { | ||||||||
it('Should comment gasless (encrypted)', 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(); | ||||||||
} | ||||||||
|
||||||||
const innercall = commentBox.interface.encodeFunctionData('comment', [ | ||||||||
'Hello, free world!', | ||||||||
]); | ||||||||
await commentGasless('Hello, c10l world', false); | ||||||||
}); | ||||||||
|
||||||||
// Sapphire Mainnet/Testnet: Wait a few moments for nodes to catch up. | ||||||||
if (chainId == BigInt(23294) || chainId == BigInt(23295)) { | ||||||||
await new Promise((r) => setTimeout(r, 6_000)); | ||||||||
it('Should comment gasless (plain)', 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(); | ||||||||
} | ||||||||
|
||||||||
const tx = await gasless.makeProxyTx( | ||||||||
await commentBox.getAddress(), | ||||||||
innercall, | ||||||||
); | ||||||||
|
||||||||
// TODO: https://github.com/oasisprotocol/sapphire-paratime/issues/179 | ||||||||
const response = await provider.broadcastTransaction(tx); | ||||||||
await response.wait(); | ||||||||
|
||||||||
const receipt = await provider.getTransactionReceipt(response.hash); | ||||||||
if (!receipt || receipt.status != 1) throw new Error('tx failed'); | ||||||||
await commentGasless('Hello, plain world', true); | ||||||||
}); | ||||||||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Based on some of my quick testing I believe it is not about matching, but actually things fail without this optimization enabled.
For example, removing this optimization in contracts/hardhat.config.ts makes the tests in contracts/ fail as well.
Do we know why this happens? Should someone investigate this further?