Skip to content

Commit

Permalink
Update scripts to fit new contract storage api
Browse files Browse the repository at this point in the history
  • Loading branch information
huyminh1115 committed Jan 24, 2024
1 parent 5bd4aa5 commit 2091e9a
Show file tree
Hide file tree
Showing 15 changed files with 11,069 additions and 11,050 deletions.
20,690 changes: 10,345 additions & 10,345 deletions package-lock.json

Large diffs are not rendered by default.

50 changes: 26 additions & 24 deletions src/contracts/Campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,36 +273,38 @@ export class CampaignContract extends SmartContract {
// eslint-disable-next-line @typescript-eslint/no-empty-function
@method updateCampaignInfo(input: UpdateCampaignInput) {}

@method rollup(proof: CampaignProof) {
proof.verify();
let ownerTreeRoot = this.ownerTreeRoot.getAndRequireEquals();
let infoTreeRoot = this.infoTreeRoot.getAndRequireEquals();
let statusTreeRoot = this.statusTreeRoot.getAndRequireEquals();
let configTreeRoot = this.configTreeRoot.getAndRequireEquals();
let lastRolledUpActionState =
this.lastRolledUpActionState.getAndRequireEquals();

ownerTreeRoot.assertEquals(proof.publicOutput.initialOwnerTreeRoot);
infoTreeRoot.assertEquals(proof.publicOutput.initialInfoTreeRoot);
statusTreeRoot.assertEquals(proof.publicOutput.initialStatusTreeRoot);
configTreeRoot.assertEquals(proof.publicOutput.initialConfigTreeRoot);
lastRolledUpActionState.assertEquals(
proof.publicOutput.initialLastRolledUpACtionState
);
@method rollup(proof: CampaignProof) {
proof.verify();
let ownerTreeRoot = this.ownerTreeRoot.getAndRequireEquals();
let infoTreeRoot = this.infoTreeRoot.getAndRequireEquals();
let statusTreeRoot = this.statusTreeRoot.getAndRequireEquals();
let configTreeRoot = this.configTreeRoot.getAndRequireEquals();
let nextCampaignId = this.nextCampaignId.getAndRequireEquals();
let lastRolledUpActionState =
this.lastRolledUpActionState.getAndRequireEquals();

ownerTreeRoot.assertEquals(proof.publicOutput.initialOwnerTreeRoot);
infoTreeRoot.assertEquals(proof.publicOutput.initialInfoTreeRoot);
statusTreeRoot.assertEquals(proof.publicOutput.initialStatusTreeRoot);
configTreeRoot.assertEquals(proof.publicOutput.initialConfigTreeRoot);
nextCampaignId.assertEquals(proof.publicOutput.initialNextCampaignId);
lastRolledUpActionState.assertEquals(
proof.publicOutput.initialLastRolledUpACtionState
);

let lastActionState = this.account.actionState.getAndRequireEquals();
lastActionState.assertEquals(
proof.publicOutput.finalLastRolledUpActionState
);

// update on-chain state
this.ownerTreeRoot.set(proof.publicOutput.finalOwnerTreeRoot);
this.infoTreeRoot.set(proof.publicOutput.finalInfoTreeRoot);
this.statusTreeRoot.set(proof.publicOutput.finalStatusTreeRoot);
this.configTreeRoot.set(proof.publicOutput.finalConfigTreeRoot);
this.lastRolledUpActionState.set(
proof.publicOutput.finalLastRolledUpActionState
);
// update on-chain state
this.ownerTreeRoot.set(proof.publicOutput.finalOwnerTreeRoot);
this.infoTreeRoot.set(proof.publicOutput.finalInfoTreeRoot);
this.statusTreeRoot.set(proof.publicOutput.finalStatusTreeRoot);
this.configTreeRoot.set(proof.publicOutput.finalConfigTreeRoot);
this.lastRolledUpActionState.set(
proof.publicOutput.finalLastRolledUpActionState
);

this.emitEvent(
EventEnum.CAMPAIGN_CREATED,
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/CampaignStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const enum StatusEnum {
APPLICATION,
FUNDING,
ALLOCATED,
FINALIZE_ROUND_1, // check this again
ENDED, // check this again
__LENGTH,
}

Expand All @@ -190,7 +190,7 @@ export function getStatusFromNumber(num: number): StatusEnum {
case 3:
return StatusEnum.ALLOCATED;
case 4:
return StatusEnum.FINALIZE_ROUND_1;
return StatusEnum.ENDED;
default:
throw new Error('Invalid number');
}
Expand Down
7 changes: 3 additions & 4 deletions src/contracts/ParticipationStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ export abstract class ParticipationCStorage<RawLeaf> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
abstract calculateLevel1Index(args: any): Field;

getLevel1Witness(level1Index: Field): Level1Witness {
return new Level1Witness(
getLevel1Witness(level1Index: Field): Level1CWitness {
return new Level1CWitness(
this._level1.getWitness(level1Index.toBigInt())
);
}

getWitness(level1Index: Field): Level1Witness {
getWitness(level1Index: Field): Level1CWitness {
return this.getLevel1Witness(level1Index);
}

Expand All @@ -96,7 +96,6 @@ export abstract class ParticipationCStorage<RawLeaf> {
};
}
}

export abstract class ParticipationStorage<RawLeaf> {
private _level1: Level1MT;
private _leafs: {
Expand Down
12 changes: 5 additions & 7 deletions src/scripts/Campaign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Cache,
SmartContract,
} from 'o1js';
import fs from 'fs';
import fs from 'fs/promises';
import { getProfiler } from './helper/profiler.js';
import {
CampaignAction,
Expand Down Expand Up @@ -47,8 +47,8 @@ describe('Campaign', () => {

let accounts: Key[] = Local.testAccounts.slice(1, 5);
let feePayerKey: Key = accounts[0];
let contracts: ContractList;
let actions: CampaignAction[];
let contracts: ContractList = {};
let actions: CampaignAction[] = [];

let zkAppAddressess = {};

Expand All @@ -61,7 +61,7 @@ describe('Campaign', () => {

beforeAll(async () => {
let configJson: Config = JSON.parse(
fs.readFileSync('config.json', 'utf8')
await fs.readFile('config.json', 'utf8')
);

await Promise.all(
Expand All @@ -71,7 +71,7 @@ describe('Campaign', () => {
let config = configJson.deployAliases[e.toLowerCase()];
// console.log(config);
let keyBase58: { privateKey: string; publicKey: string } =
JSON.parse(fs.readFileSync(config.keyPath, 'utf8'));
JSON.parse(await fs.readFile(config.keyPath, 'utf8'));
let key = {
privateKey: PrivateKey.fromBase58(keyBase58.privateKey),
publicKey: PublicKey.fromBase58(keyBase58.publicKey),
Expand Down Expand Up @@ -108,8 +108,6 @@ describe('Campaign', () => {
);
});

// beforeEach(() => {});

it('should compile programs and contracts', async () => {
await compile(CreateCampaign, cache, logMemory, profiler);
if (doProofs) {
Expand Down
Loading

0 comments on commit 2091e9a

Please sign in to comment.