Skip to content

Commit 30fef94

Browse files
committed
Refactor method calls to destructure results in account contract and note creation scripts
1 parent 79db1e7 commit 30fef94

File tree

7 files changed

+34
-34
lines changed

7 files changed

+34
-34
lines changed

account-contract/ts/deploy-account-contract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const { estimatedGas, stats } = await accountContractDeployMethod.simulate(deplo
7575
console.log(estimatedGas);
7676
console.log(stats);
7777

78-
const deployedAccountContract = await accountContractDeployMethod.send(deployAccountOpts);
78+
const { contract: deployedAccountContract } = await accountContractDeployMethod.send(deployAccountOpts);
7979

8080
console.log('PasswordAccount contract deployed at:', deployedAccountContract.address);
8181

note-send-proof/scripts/generate_data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function main() {
4444
const NOTE_VALUE = 69n;
4545

4646
console.log('Creating note for user...');
47-
const receipt = await gettingStarted.methods
47+
const { receipt } = await gettingStarted.methods
4848
.create_note_for_user(NOTE_VALUE)
4949
.send({ from: deployerAddress });
5050
console.log('TX HASH', receipt.txHash.toString());

note-send-proof/scripts/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ console.log('CONTRACT DEPLOYED AT', gettingStarted.address);
3535

3636
const NOTE_VALUE = 69;
3737

38-
const receipt = await gettingStarted.methods.create_note_for_user(NOTE_VALUE).send({ from: deployerAddress });
38+
const { receipt } = await gettingStarted.methods.create_note_for_user(NOTE_VALUE).send({ from: deployerAddress });
3939

4040
console.log('TX HASH', receipt.txHash);
4141

note-send-proof/tests/note_creation.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('Note Hash Computation Verification', () => {
6666
const NOTE_VALUE = 69n;
6767

6868
// Create note
69-
const receipt = await gettingStartedContract.methods
69+
const { receipt } = await gettingStartedContract.methods
7070
.create_note_for_user(NOTE_VALUE)
7171
.send({ from: deployer });
7272

@@ -121,7 +121,7 @@ describe('Note Hash Computation Verification', () => {
121121
const NOTE_VALUE = 42n;
122122

123123
// Create note with different value
124-
const receipt = await gettingStartedContract.methods
124+
const { receipt } = await gettingStartedContract.methods
125125
.create_note_for_user(NOTE_VALUE)
126126
.send({ from: deployer });
127127

prediction-market/tests/prediction_market.test.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ describe("Prediction Market Contract - Full Privacy", () => {
7373
}, TEST_TIMEOUT)
7474

7575
test("should have initial 50/50 prices", async () => {
76-
const yesPrice = await market.methods.get_price(true).simulate({ from: adminAddress })
77-
const noPrice = await market.methods.get_price(false).simulate({ from: adminAddress })
76+
const { result: yesPrice } = await market.methods.get_price(true).simulate({ from: adminAddress })
77+
const { result: noPrice } = await market.methods.get_price(false).simulate({ from: adminAddress })
7878

7979
expect(yesPrice).toBe(PRICE_PRECISION / 2n)
8080
expect(noPrice).toBe(PRICE_PRECISION / 2n)
@@ -87,13 +87,13 @@ describe("Prediction Market Contract - Full Privacy", () => {
8787
const depositAmount = 2000n
8888

8989
// deposit() is now a PRIVATE function - creates private collateral notes
90-
const tx = await market.methods.deposit(depositAmount)
90+
const { receipt: tx } = await market.methods.deposit(depositAmount)
9191
.send({ from: aliceAddress })
9292

9393
expect(tx.executionResult).toBe('success')
9494

9595
// Collateral balance is now private (sums private notes)
96-
const balance = await market.methods.get_collateral_balance(aliceAddress).simulate({ from: aliceAddress })
96+
const { result: balance } = await market.methods.get_collateral_balance(aliceAddress).simulate({ from: aliceAddress })
9797
expect(balance).toBe(depositAmount)
9898

9999
console.log(`Alice deposited ${depositAmount} PRIVATELY, balance: ${balance}`)
@@ -105,7 +105,7 @@ describe("Prediction Market Contract - Full Privacy", () => {
105105

106106
// buy_outcome consumes private collateral, creates partial note for shares
107107
// The public function does NOT receive Alice's address - FULL PRIVACY!
108-
const tx = await market.methods.buy_outcome(
108+
const { receipt: tx } = await market.methods.buy_outcome(
109109
true, // is_yes
110110
buyAmount,
111111
minShares,
@@ -115,20 +115,20 @@ describe("Prediction Market Contract - Full Privacy", () => {
115115
console.log("Alice bought YES with FULL PRIVACY (public function doesn't know who)")
116116

117117
// Check private collateral was deducted
118-
const collateralBalance = await market.methods.get_collateral_balance(aliceAddress).simulate({ from: aliceAddress })
118+
const { result: collateralBalance } = await market.methods.get_collateral_balance(aliceAddress).simulate({ from: aliceAddress })
119119
expect(collateralBalance).toBe(1500n) // 2000 - 500
120120

121121
// Check private YES balance
122-
const yesBalance = await market.methods.get_yes_balance(aliceAddress).simulate({ from: aliceAddress })
122+
const { result: yesBalance } = await market.methods.get_yes_balance(aliceAddress).simulate({ from: aliceAddress })
123123
expect(yesBalance).toBeGreaterThanOrEqual(minShares)
124124

125125
console.log(`Alice's private collateral: ${collateralBalance}`)
126126
console.log(`Alice's private YES balance: ${yesBalance}`)
127127
}, TEST_TIMEOUT)
128128

129129
test("YES price should have increased after alice's purchase", async () => {
130-
const yesPrice = await market.methods.get_price(true).simulate({ from: adminAddress })
131-
const noPrice = await market.methods.get_price(false).simulate({ from: adminAddress })
130+
const { result: yesPrice } = await market.methods.get_price(true).simulate({ from: adminAddress })
131+
const { result: noPrice } = await market.methods.get_price(false).simulate({ from: adminAddress })
132132

133133
expect(yesPrice).toBeGreaterThan(PRICE_PRECISION / 2n)
134134
expect(noPrice).toBeLessThan(PRICE_PRECISION / 2n)
@@ -149,7 +149,7 @@ describe("Prediction Market Contract - Full Privacy", () => {
149149
.send({ from: bobAddress })
150150

151151
// Bob buys NO with full privacy
152-
const tx = await market.methods.buy_outcome(
152+
const { receipt: tx } = await market.methods.buy_outcome(
153153
false, // is_yes = false (NO)
154154
buyAmount,
155155
0n, // no slippage protection for this test
@@ -158,17 +158,17 @@ describe("Prediction Market Contract - Full Privacy", () => {
158158
expect(tx.executionResult).toBe('success')
159159
console.log("Bob bought NO with FULL PRIVACY")
160160

161-
const noBalance = await market.methods.get_no_balance(bobAddress).simulate({ from: bobAddress })
161+
const { result: noBalance } = await market.methods.get_no_balance(bobAddress).simulate({ from: bobAddress })
162162
expect(noBalance).toBeGreaterThan(0n)
163163

164164
console.log(`Bob's private NO balance: ${noBalance}`)
165165
}, TEST_TIMEOUT)
166166

167167
test("alice and bob should have separate private balances", async () => {
168-
const aliceYes = await market.methods.get_yes_balance(aliceAddress).simulate({ from: aliceAddress })
169-
const aliceNo = await market.methods.get_no_balance(aliceAddress).simulate({ from: aliceAddress })
170-
const bobYes = await market.methods.get_yes_balance(bobAddress).simulate({ from: bobAddress })
171-
const bobNo = await market.methods.get_no_balance(bobAddress).simulate({ from: bobAddress })
168+
const { result: aliceYes } = await market.methods.get_yes_balance(aliceAddress).simulate({ from: aliceAddress })
169+
const { result: aliceNo } = await market.methods.get_no_balance(aliceAddress).simulate({ from: aliceAddress })
170+
const { result: bobYes } = await market.methods.get_yes_balance(bobAddress).simulate({ from: bobAddress })
171+
const { result: bobNo } = await market.methods.get_no_balance(bobAddress).simulate({ from: bobAddress })
172172

173173
expect(aliceYes).toBeGreaterThan(0n)
174174
expect(aliceNo).toBe(0n)
@@ -180,24 +180,24 @@ describe("Prediction Market Contract - Full Privacy", () => {
180180
}, TEST_TIMEOUT)
181181

182182
test("alice should be able to withdraw remaining collateral PRIVATELY", async () => {
183-
const balanceBefore = await market.methods.get_collateral_balance(aliceAddress).simulate({ from: aliceAddress })
183+
const { result: balanceBefore } = await market.methods.get_collateral_balance(aliceAddress).simulate({ from: aliceAddress })
184184
const withdrawAmount = 500n
185185

186186
// withdraw() is now a PRIVATE function
187-
const tx = await market.methods.withdraw(withdrawAmount)
187+
const { receipt: tx } = await market.methods.withdraw(withdrawAmount)
188188
.send({ from: aliceAddress })
189189

190190
expect(tx.executionResult).toBe('success')
191191

192-
const balanceAfter = await market.methods.get_collateral_balance(aliceAddress).simulate({ from: aliceAddress })
192+
const { result: balanceAfter } = await market.methods.get_collateral_balance(aliceAddress).simulate({ from: aliceAddress })
193193
expect(balanceAfter).toBe(balanceBefore - withdrawAmount)
194194

195195
console.log(`Alice withdrew ${withdrawAmount} PRIVATELY, balance: ${balanceAfter}`)
196196
}, TEST_TIMEOUT)
197197

198198
test("prices should always sum to ~100%", async () => {
199-
const yesPrice = await market.methods.get_price(true).simulate({ from: adminAddress })
200-
const noPrice = await market.methods.get_price(false).simulate({ from: adminAddress })
199+
const { result: yesPrice } = await market.methods.get_price(true).simulate({ from: adminAddress })
200+
const { result: noPrice } = await market.methods.get_price(false).simulate({ from: adminAddress })
201201
// Allow for small rounding error (integer division)
202202
const priceSum = yesPrice + noPrice
203203
expect(priceSum).toBeGreaterThanOrEqual(PRICE_PRECISION - 1n)

recursive_verification/scripts/run_recursion.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,16 @@ async function main() {
9595

9696
await captureProfile(interaction, opts, "recursion");
9797

98-
let counterValue = await valueNotEqual.methods
98+
let counterValue = (await valueNotEqual.methods
9999
.get_counter(accounts[0].item)
100-
.simulate({ from: accounts[0].item });
100+
.simulate({ from: accounts[0].item })).result;
101101
console.log(`Counter value: ${counterValue}`);
102102

103103
await interaction.send(opts);
104104

105-
counterValue = await valueNotEqual.methods
105+
counterValue = (await valueNotEqual.methods
106106
.get_counter(accounts[0].item)
107-
.simulate({ from: accounts[0].item });
107+
.simulate({ from: accounts[0].item })).result;
108108
console.log(`Counter value: ${counterValue}`);
109109

110110
assert(counterValue === 11n);

recursive_verification/tests/recursive_verification.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe("Recursive Verification", () => {
9191
}
9292

9393
// Call increment with proof data (vk_hash is read from storage)
94-
const tx = await valueNotEqualContract.methods.increment(
94+
const { receipt: tx } = await valueNotEqualContract.methods.increment(
9595
ownerAddress,
9696
data.vkAsFields as unknown as FieldLike[],
9797
data.proofAsFields as unknown as FieldLike[],
@@ -106,7 +106,7 @@ describe("Recursive Verification", () => {
106106
}, TEST_TIMEOUT)
107107

108108
test("should read incremented counter value", async () => {
109-
const counterValue = await valueNotEqualContract.methods.get_counter(
109+
const { result: counterValue } = await valueNotEqualContract.methods.get_counter(
110110
ownerAddress
111111
).simulate({ from: ownerAddress })
112112

@@ -123,7 +123,7 @@ describe("Recursive Verification", () => {
123123
}
124124

125125
// Second increment to verify the contract works multiple times
126-
const tx = await valueNotEqualContract.methods.increment(
126+
const { receipt: tx } = await valueNotEqualContract.methods.increment(
127127
ownerAddress,
128128
data.vkAsFields as unknown as FieldLike[],
129129
data.proofAsFields as unknown as FieldLike[],
@@ -134,7 +134,7 @@ describe("Recursive Verification", () => {
134134
expect(tx.executionResult).toBe(TxExecutionResult.SUCCESS)
135135

136136
// Check counter value is now 12
137-
const counterValue = await valueNotEqualContract.methods.get_counter(
137+
const { result: counterValue } = await valueNotEqualContract.methods.get_counter(
138138
ownerAddress
139139
).simulate({ from: ownerAddress })
140140

@@ -180,7 +180,7 @@ describe("Recursive Verification", () => {
180180
data.publicInputs as unknown as FieldLike[],
181181
).send(sendOpts)
182182
// Check user1's counter
183-
const user1Counter = await user1Contract.methods.get_counter(
183+
const { result: user1Counter } = await user1Contract.methods.get_counter(
184184
user1Address
185185
).simulate({ from: user1Address })
186186

0 commit comments

Comments
 (0)