Skip to content

Commit

Permalink
Merge pull request #5 from o1-labs-XT/devnet-test
Browse files Browse the repository at this point in the history
Add devnet and stress test
  • Loading branch information
boray authored Oct 19, 2024
2 parents 79a7839 + df6afed commit 2bcfc49
Show file tree
Hide file tree
Showing 31 changed files with 2,215 additions and 2,879 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ jobs:
run: |
pushd contracts
npm ci
npm i @rollup/rollup-linux-x64-gnu
npm test
popd
- name: Settlement tests
run: |
pushd settlement
npm ci
npm i @rollup/rollup-linux-x64-gnu
npm test
popd
env:
Expand Down
12 changes: 1 addition & 11 deletions contracts/config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
{
"version": 1,
"deployAliases": {
"devnet": {
"networkId": "testnet",
"url": "https://api.minascan.io/node/devnet/v1/graphql",
"keyPath": "keys/devnet.json",
"feepayerKeyPath": "/Users/boraysaygilier/.cache/zkapp-cli/keys/berkkey.json",
"feepayerAlias": "berkkey",
"fee": "0.1",
"smartContract": "NameService"
}
}
"deployAliases": {}
}
1,319 changes: 9 additions & 1,310 deletions contracts/package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"devDependencies": {
"@babel/preset-env": "^7.16.4",
"@babel/preset-typescript": "^7.16.0",
"@types/node": "^22.5.5",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"eslint": "^8.7.0",
Expand All @@ -34,6 +35,9 @@
"typescript": "^5.5",
"vitest": "^2.1.0"
},
"peerDependencies": {
"o1js": "1.8.0"
},
"engines": {
"node": ">=18.14.0"
},
Expand Down
12 changes: 6 additions & 6 deletions contracts/src/NameService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AdminChangedEvent extends Struct({

const offchainState = OffchainState(
{
registry: OffchainState.Map(Field, NameRecord),
registry: OffchainState.Map(Name, NameRecord),
premium: OffchainState.Field(UInt64),
},
{ logTotalCapacity: 10, maxActionsPerProof: 5 }
Expand Down Expand Up @@ -110,7 +110,7 @@ class NameService extends SmartContract {
* @param record
*
*/
@method async register_name(name: Field, record: NameRecord) {
@method async register_name(name: Name, record: NameRecord) {
(await offchainState.fields.registry.get(name)).isSome.assertFalse(); // do we need this?
let premium = await this.premium_rate();
const sender = this.sender.getAndRequireSignature();
Expand All @@ -132,7 +132,7 @@ class NameService extends SmartContract {
* @param new_record
*
*/
@method async set_record(name: Field, new_record: NameRecord) {
@method async set_record(name: Name, new_record: NameRecord) {
let current_record = (
await offchainState.fields.registry.get(name)
).assertSome('this name is not owned');
Expand All @@ -154,7 +154,7 @@ class NameService extends SmartContract {
* @param new_owner
*
*/
@method async transfer_name_ownership(name: Field, new_owner: PublicKey) {
@method async transfer_name_ownership(name: Name, new_owner: PublicKey) {
let current_record = (
await offchainState.fields.registry.get(name)
).assertSome('this name is not owned');
Expand All @@ -175,7 +175,7 @@ class NameService extends SmartContract {
* @param name
* @returns owner of given name
*/
@method.returns(PublicKey) async owner_of(name: Field) {
@method.returns(PublicKey) async owner_of(name: Name) {
return (await offchainState.fields.registry.get(name)).assertSome(
'this name is not owned'
).mina_address;
Expand All @@ -185,7 +185,7 @@ class NameService extends SmartContract {
* @param name
* @returns full record associated with given name
*/
@method.returns(NameRecord) async resolve_name(name: Field) {
@method.returns(NameRecord) async resolve_name(name: Name) {
return (await offchainState.fields.registry.get(name)).assertSome(
'this name is not owned'
);
Expand Down
134 changes: 0 additions & 134 deletions contracts/src/push_actions.ts

This file was deleted.

119 changes: 119 additions & 0 deletions contracts/src/scripts/integration-test/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import fs from 'fs/promises';
import {
AccountUpdate,
Field,
Mina,
PrivateKey,
UInt64,
NetworkId,
} from 'o1js';
import {
NameService,
NameRecord,
offchainState,
Name,
} from '../../NameService.js';

// check command line arg
let deployAlias = process.argv[2];
if (!deployAlias) throw Error(`Missing <deployAlias> argument`);
Error.stackTraceLimit = 1000;
const DEFAULT_NETWORK_ID = 'testnet';

// parse config and private key from file
type Config = {
deployAliases: Record<
string,
{
networkId?: string;
url: string;
keyPath: string;
fee: string;
feepayerKeyPath: string;
feepayerAlias: string;
}
>;
};
let configJson: Config = JSON.parse(await fs.readFile('config.json', 'utf8'));
let config = configJson.deployAliases[deployAlias];
let feepayerKeysBase58: { privateKey: string; publicKey: string } = JSON.parse(
await fs.readFile(config.feepayerKeyPath, 'utf8')
);
let zkAppKeysBase58: { privateKey: string; publicKey: string } = JSON.parse(
await fs.readFile(config.keyPath, 'utf8')
);

let feepayerKey = PrivateKey.fromBase58(feepayerKeysBase58.privateKey);
let zkAppKey = PrivateKey.fromBase58(zkAppKeysBase58.privateKey);

const Network = Mina.Network({
archive: 'https://api.minascan.io/archive/devnet/v1/graphql',
networkId: (config.networkId ?? DEFAULT_NETWORK_ID) as NetworkId,
mina: config.url,
});

const fee = Number(config.fee) * 1e9; // in nanomina (1 billion = 1.0 mina)
Mina.setActiveInstance(Network);
let tx;
let feepayerAddress = feepayerKey.toPublicKey();
let zkAppAddress = zkAppKey.toPublicKey();
let name_service_contract = new NameService(zkAppAddress);

console.time('compile program');
await offchainState.compile();
offchainState.setContractInstance(name_service_contract);
console.timeEnd('compile program');
console.time('compile contract');
await NameService.compile();
console.timeEnd('compile contract');

console.time('deploy');
tx = await Mina.transaction({ sender: feepayerAddress, fee: fee }, async () => {
AccountUpdate.fundNewAccount(feepayerAddress);
await name_service_contract.deploy();
})
.prove()
.sign([feepayerKey, zkAppKey])
.send()
.wait();
console.log(tx.toPretty());
console.timeEnd('deploy');

console.time('set premimum rate');
tx = await Mina.transaction({ sender: feepayerAddress, fee: fee }, async () => {
await name_service_contract.set_premium(UInt64.from(100));
})
.sign([feepayerKey])
.prove()
.send()
.wait();
console.log(tx.toPretty());
console.timeEnd('set premimum rate');

console.time('settlement proof');
let proof = await offchainState.createSettlementProof();
console.timeEnd('settlement proof');

console.time('settle');
tx = await Mina.transaction({ sender: feepayerAddress, fee: fee }, async () =>
name_service_contract.settle(proof)
)
.sign([feepayerKey])
.prove()
.send()
.wait();
console.log(tx.toPretty());
console.timeEnd('settle');

console.time('get premimum rate');
let res;
tx = await Mina.transaction({ sender: feepayerAddress, fee: fee }, async () => {
res = await name_service_contract.premium_rate();
})
.sign([feepayerKey])
.prove()
.send()
.wait();
console.log(tx.toPretty());
console.log(res!.toString());
console.timeEnd('get premimum rate');
Loading

0 comments on commit 2bcfc49

Please sign in to comment.