Skip to content

Commit 3c1cbf3

Browse files
committed
make tests great again
1 parent 086374a commit 3c1cbf3

File tree

12 files changed

+52
-30
lines changed

12 files changed

+52
-30
lines changed

packages/common/src/zkProgrammable/provableMethod.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { ProvableMethodExecutionContext } from "./ProvableMethodExecutionContext
55
import type { WithZkProgrammable, ZkProgrammable } from "./ZkProgrammable";
66
import { ToFieldable } from "../utils";
77

8-
export type O1JSPrimitive = InferProvable<ProvableExtended<unknown>> & ToFieldable;
8+
export type O1JSPrimitive = InferProvable<ProvableExtended<unknown>> &
9+
ToFieldable;
910
export type ArgumentTypes = (O1JSPrimitive | Proof<unknown, unknown>)[];
1011

1112
// eslint-disable-next-line etc/prefer-interface

packages/module/src/method/MethodParameterEncoder.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
/* eslint-disable no-underscore-dangle */
2-
import { Field, FlexibleProvable, Proof, ProvableExtended } from "o1js";
2+
import {
3+
Field,
4+
FlexibleProvable,
5+
Proof,
6+
Provable,
7+
ProvableExtended,
8+
} from "o1js";
39
import {
410
ArgumentTypes,
511
ProofTypes,
@@ -118,13 +124,16 @@ export class MethodParameterEncoder {
118124
return argumentType.toFields(argument);
119125
});
120126

121-
const argsJSON = args.map((argument, index) => {
122-
if (argument instanceof Proof) {
123-
return JSON.stringify(argument.toJSON());
124-
}
127+
let argsJSON: string[] = [];
128+
Provable.asProver(() => {
129+
argsJSON = args.map((argument, index) => {
130+
if (argument instanceof Proof) {
131+
return JSON.stringify(argument.toJSON());
132+
}
125133

126-
const argumentType = this.types[index] as ToJSONableStatic;
127-
return JSON.stringify(argumentType.toJSON(argument));
134+
const argumentType = this.types[index] as ToJSONableStatic;
135+
return JSON.stringify(argumentType.toJSON(argument));
136+
});
128137
});
129138

130139
return {

packages/module/src/method/runtimeMethod.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export function toWrappedMethod(
6969
this: RuntimeModule<unknown>,
7070
methodName: string,
7171
moduleMethod: (...args: ArgumentTypes) => unknown,
72-
methodArguments: ArgumentTypes,
7372
options: {
7473
invocationType: RuntimeMethodInvocationType;
7574
}
@@ -121,11 +120,11 @@ export function toWrappedMethod(
121120
).encode(args);
122121

123122
// Assert that the argsHash that has been signed matches the given arguments
124-
// We can use js-if here, because methodArguments is statically sizes
123+
// We can use js-if here, because args are statically sized
125124
// i.e. the result of the if-statement will be the same for all executions
126125
// of this method
127126
const argsHash =
128-
(methodArguments ?? []).length > 0 ? Poseidon.hash(argsFields) : Field(0);
127+
(args ?? []).length > 0 ? Poseidon.hash(argsFields) : Field(0);
129128

130129
transaction.argsHash.assertEquals(
131130
argsHash,
@@ -237,7 +236,6 @@ function runtimeMethodInternal(options: {
237236
const simulatedWrappedMethod = Reflect.apply(toWrappedMethod, this, [
238237
methodName,
239238
simulatedMethod,
240-
args,
241239
options,
242240
]);
243241

packages/module/src/runtime/Runtime.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
import {
2323
combineMethodName,
2424
isRuntimeMethod,
25+
runtimeMethodTypeMetadataKey,
2526
toWrappedMethod,
2627
WrappedMethod,
2728
} from "../method/runtimeMethod";
@@ -128,10 +129,16 @@ export class RuntimeZkProgrammable<
128129
methodName
129130
);
130131
const method = modulePrototype[methodName];
132+
const invocationType = Reflect.getMetadata(
133+
runtimeMethodTypeMetadataKey,
134+
runtimeModule,
135+
methodName
136+
);
137+
131138
const wrappedMethod = Reflect.apply(
132139
toWrappedMethod,
133140
runtimeModule,
134-
[methodName, method]
141+
[methodName, method, { invocationType }]
135142
);
136143

137144
// eslint-disable-next-line no-warning-comments

packages/sdk/src/appChain/TestingAppChain.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,4 @@ export class TestingAppChain<
149149

150150
return await blockTrigger.produceUnproven();
151151
}
152-
153-
public async start() {
154-
log.setLevel("ERROR");
155-
super.start();
156-
}
157152
}

packages/sdk/test/TestingAppChain.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable max-statements */
22
import "reflect-metadata";
3-
import { PrivateKey, PublicKey, UInt64 } from "o1js";
3+
import { PrivateKey, Provable, PublicKey, UInt64 } from "o1js";
44
import {
55
runtimeMethod,
66
RuntimeModule,
@@ -17,6 +17,7 @@ import {
1717
TokenId,
1818
VanillaRuntimeModules,
1919
} from "@proto-kit/library";
20+
import { log } from "@proto-kit/common";
2021

2122
export interface AdminConfig {
2223
admin: PublicKey;
@@ -125,6 +126,8 @@ describe("testing app chain", () => {
125126
// start the chain, sequencer is now accepting transactions
126127
await appChain.start();
127128

129+
log.setLevel("INFO");
130+
128131
/**
129132
* Setup the transaction signer / sender
130133
*/
@@ -148,9 +151,9 @@ describe("testing app chain", () => {
148151
*/
149152
const block = await appChain.produceBlock();
150153

151-
expect(block?.transactions[0].status.toBoolean()).toBe(true);
154+
Provable.log("block", block);
152155

153-
appChain.query.runtime.Balances;
156+
expect(block?.transactions[0].status.toBoolean()).toBe(true);
154157

155158
/**
156159
* Observe new state after the block has been produced

packages/sdk/test/blockProof/blockProof.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Bool, PrivateKey, UInt64 } from "o1js";
1+
import { Bool, PrivateKey, Provable, UInt64 } from "o1js";
22
import {
33
PublicKeyOption,
44
RuntimeMethodExecutionContext,

packages/sdk/test/fees.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Faucet extends RuntimeModule<unknown> {
2727
public drip() {
2828
this.balances.mint(
2929
new TokenId(0),
30-
this.transaction.sender,
30+
this.transaction.sender.value,
3131
UInt64.from(1000)
3232
);
3333
}
@@ -41,7 +41,7 @@ class Pit extends RuntimeModule<unknown> {
4141

4242
@runtimeMethod()
4343
public burn(amount: UInt64) {
44-
this.balances.burn(new TokenId(0), this.transaction.sender, amount);
44+
this.balances.burn(new TokenId(0), this.transaction.sender.value, amount);
4545
}
4646
}
4747

packages/sdk/test/modularization.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AppChain, AppChainModule } from "../src";
1111
import { Protocol, ProtocolModule } from "@proto-kit/protocol";
1212
import { VanillaProtocolModules } from "@proto-kit/library";
1313
import { Sequencer, SequencerModule } from "@proto-kit/sequencer";
14+
import { PrivateKey } from "o1js";
1415

1516
class TestRuntimeModule extends RuntimeModule<object> {
1617
public initialized = false;
@@ -80,12 +81,19 @@ describe("modularization", () => {
8081
TestRuntimeModule: {},
8182
},
8283
Protocol: {
83-
TestProtocolModule: {},
84+
AccountState: {},
8485
BlockProver: {},
8586
StateTransitionProver: {},
86-
AccountState: {},
8787
BlockHeight: {},
88-
TransactionFee: {} as any,
88+
LastStateRoot: {},
89+
TransactionFee: {
90+
tokenId: 0n,
91+
feeRecipient: PrivateKey.random().toPublicKey().toBase58(),
92+
baseFee: 0n,
93+
perWeightUnitFee: 0n,
94+
methods: {},
95+
},
96+
TestProtocolModule: {},
8997
},
9098
Sequencer: {
9199
TestSequencerModule: {},

packages/sequencer/src/protocol/production/unproven/TransactionExecutionService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export class TransactionExecutionService {
271271
}
272272
} catch (error) {
273273
if (error instanceof Error) {
274-
log.info("Error in inclusion of tx, skipping", error);
274+
log.error("Error in inclusion of tx, skipping", error);
275275
}
276276
}
277277
}

0 commit comments

Comments
 (0)