Skip to content

Commit

Permalink
fix provable tests and asyncing code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
45930 committed Apr 14, 2024
1 parent 3ce669e commit a325b59
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 179 deletions.
16 changes: 8 additions & 8 deletions examples/smart_contract/election/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Election extends SmartContract {
@state(Ballot) ballot3 = State<Ballot>();
@state(Ballot) ballot4 = State<Ballot>();

init() {
async init() {
super.init();
this.ballot1.set(Ballot.fromBigInts([0n, 0n, 0n, 0n, 0n, 0n, 0n]));
this.ballot2.set(Ballot.fromBigInts([0n, 0n, 0n, 0n, 0n, 0n, 0n]));
Expand All @@ -18,9 +18,9 @@ export class Election extends SmartContract {
}

@method
castBallot1(vote: Ballot) {
async castBallot1(vote: Ballot) {
const unpackedVote = Ballot.unpack(vote.packed);
const ballot1 = this.ballot1.getAndAssertEquals();
const ballot1 = this.ballot1.getAndRequireEquals();
const unpackedBallot1 = Ballot.unpack(ballot1.packed);

let voteSum = UInt32.from(0);
Expand All @@ -33,9 +33,9 @@ export class Election extends SmartContract {
}

@method
castBallot2(vote: Ballot) {
async castBallot2(vote: Ballot) {
const unpackedVote = Ballot.unpack(vote.packed);
const ballot2 = this.ballot2.getAndAssertEquals();
const ballot2 = this.ballot2.getAndRequireEquals();
const unpackedBallot2 = Ballot.unpack(ballot2.packed);

let voteSum = UInt32.from(0);
Expand All @@ -50,7 +50,7 @@ export class Election extends SmartContract {
@method
castBallot3(vote: Ballot) {
const unpackedVote = Ballot.unpack(vote.packed);
const ballot3 = this.ballot3.getAndAssertEquals();
const ballot3 = this.ballot3.getAndRequireEquals();
const unpackedBallot3 = Ballot.unpack(ballot3.packed);

let voteSum = UInt32.from(0);
Expand All @@ -63,9 +63,9 @@ export class Election extends SmartContract {
}

@method
castBallot4(vote: Ballot) {
async castBallot4(vote: Ballot) {
const unpackedVote = Ballot.unpack(vote.packed);
const ballot4 = this.ballot4.getAndAssertEquals();
const ballot4 = this.ballot4.getAndRequireEquals();
const unpackedBallot4 = Ballot.unpack(ballot4.packed);

let voteSum = UInt32.from(0);
Expand Down
7 changes: 0 additions & 7 deletions examples/smart_contract/tokenState/README.md

This file was deleted.

62 changes: 0 additions & 62 deletions examples/smart_contract/tokenState/contract.ts

This file was deleted.

71 changes: 0 additions & 71 deletions examples/smart_contract/tokenState/run.ts

This file was deleted.

13 changes: 6 additions & 7 deletions examples/zk_program/age_gate/circuit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {
Field,
Experimental,
ZkProgram,
UInt32,
Provable,
Poseidon,
SelfProof,
Character,
Bool,
Empty,
} from 'o1js';
Expand Down Expand Up @@ -34,19 +32,20 @@ const isOlderThan = (reference: PackedString, toVerify: PackedString): Bool => {
return ver.greaterThan(ref);
};

export const AgeGateCircuit = Experimental.ZkProgram({
export const AgeGateCircuit = ZkProgram({
name: 'AgeGateCircuit',
publicOutput: PackedCounters,

methods: {
init: {
privateInputs: [],
method() {
async method() {
return PackedCounters.fromBigInts([0n, 0n]);
},
},
verifyAge: {
privateInputs: [SelfProof, PackedString],
method(
async method(
oldProof: SelfProof<Empty, PackedCounters>,
dateToVerify: PackedString
) {
Expand All @@ -72,4 +71,4 @@ export const AgeGateCircuit = Experimental.ZkProgram({
},
});

export const AgeGateCircuitProof = Experimental.ZkProgram.Proof(AgeGateCircuit);
export const AgeGateCircuitProof = ZkProgram.Proof(AgeGateCircuit);
10 changes: 1 addition & 9 deletions src/lib/PackingPlant.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
Field,
Struct,
Poseidon,
provable,
InferProvable,
Provable,
ProvableExtended,
} from 'o1js';
import { Field, Struct, provable, InferProvable, Provable } from 'o1js';

const MAX_BITS_PER_FIELD = 254n;

Expand Down
2 changes: 1 addition & 1 deletion tests/provable/end_to_end.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
TextInputProgram,
TextInputProof,
} from './example_packed_string_circuit';
import { Character, Poseidon } from 'o1js';
import { Character } from 'o1js';

describe('End to End Votes Test', () => {
const init = [0n, 0n];
Expand Down
13 changes: 3 additions & 10 deletions tests/provable/example_packed_string_circuit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
ZkProgram,
SelfProof,
Character,
Poseidon,
Provable,
Field,
} from 'o1js';
import { ZkProgram, SelfProof, Character, Provable } from 'o1js';
import { PackedStringFactory } from '../../src/lib/packed-types/PackedString';

export class TextInput extends PackedStringFactory() {}
Expand All @@ -17,14 +10,14 @@ export const TextInputProgram = ZkProgram({
methods: {
init: {
privateInputs: [],
method(state: TextInput) {
async method(state: TextInput) {
const initState = TextInput.fromString('Mina Protocol');
state.assertEquals(initState);
},
},
changeFirstLetter: {
privateInputs: [SelfProof, Provable.Array(Character, 31), Character],
method(
async method(
newState: TextInput,
oldProof: SelfProof<TextInput, TextInput>,
oldCharacters: Array<Character>,
Expand Down
8 changes: 4 additions & 4 deletions tests/provable/example_packed_uint_circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export const VotesProgram = ZkProgram({
methods: {
init: {
privateInputs: [],
method(state: Votes) {
async method(publicInput: Votes) {
const initState = Votes.fromBigInts([0n, 0n]);
state.assertEquals(initState);
publicInput.assertEquals(initState);
},
},
incrementIndex0: {
privateInputs: [SelfProof],
method(newState: Votes, oldProof: SelfProof<Votes, Votes>) {
async method(newState: Votes, oldProof: SelfProof<Votes, Votes>) {
oldProof.verify();
const unpacked = Votes.unpack(oldProof.publicInput.packed);
unpacked[0] = unpacked[0].add(1);
Expand All @@ -26,7 +26,7 @@ export const VotesProgram = ZkProgram({
},
incrementIndex1: {
privateInputs: [SelfProof],
method(newState: Votes, oldProof: SelfProof<Votes, Votes>) {
async method(newState: Votes, oldProof: SelfProof<Votes, Votes>) {
oldProof.verify();
const unpacked = Votes.unpack(oldProof.publicInput.packed);
unpacked[1] = unpacked[1].add(1);
Expand Down

0 comments on commit a325b59

Please sign in to comment.