Skip to content

Commit

Permalink
implement contract testing and readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
dakk committed May 8, 2024
1 parent 2b08d1d commit 869ec2d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ a reward for doing sampling

The following process outlines how clients can submit quantum circuits for sampling using the DQPU contract:

1. **Client Submits Job**: A *Client* sends a quantum circuit along with a reward to the DQPU smart contract. The circuit data is uploaded to a distributed file storage system like IPFS. The smart contract adds the job to a queue in a 'pending' state with the associated reward.
1. **Client Submits Job**: A *Client* sends a quantum circuit along with a reward to the DQPU smart contract. The circuit data is uploaded to a distributed file storage system like IPFS. The smart contract adds the job to a queue in a 'pending-validation' state with the associated reward.

2. **Verifier Validates Circuit**: A *Verifier*[^1] validates the submitted circuit. This might involve checks for syntax errors or ensuring the circuit is within allowed parameters. The verifier also adds special verification elements (traps) into the circuit. Once validated, the job moves to a 'waiting' state, becomes 'invalid' otherwise.

Expand Down Expand Up @@ -121,9 +121,9 @@ dqpu-sampler --min-reward 0.0009 --sampler aersimulator
## Usage: running a verifier node
A verifier node continuously pool the DQPU smart contract waiting for new 'pending' and 'validating' jobs. When a new job appear, the verifiers:
- 'pending' job are checked for quantum circuit validity, and trap qubits are inserted
- 'validating' job are checked for trap verification
A verifier node continuously pool the DQPU smart contract waiting for new 'pending-validation' and 'validating-result' jobs. When a new job appear, the verifiers:
- 'pending-validation' job are checked for quantum circuit validity, and trap qubits are inserted
- 'validating-result' job are checked for trap verification
After every validation, the verifier receives a percentage of the job reward.
Expand Down
3 changes: 2 additions & 1 deletion dqpu-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"type": "module",
"scripts": {
"build": "near-sdk-js build src/contract.ts build/dqpu.wasm",
"test": "$npm_execpath run build && ava -- ./build/dqpu.wasm"
"test": "$npm_execpath run build && ava -- ./build/dqpu.wasm",
"only-test": "ava -- ./build/dqpu.wasm"
},
"dependencies": {
"near-cli": "^4.0.8",
Expand Down
18 changes: 13 additions & 5 deletions dqpu-contract/sandbox-ts/main.ava.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ test.beforeEach(async (t) => {
process.argv[2],
);

await contract.call(contract, "init", {})

// Save state for test runs, it is unique for each test
t.context.accounts = { root, contract };
});
Expand All @@ -43,11 +45,17 @@ test.afterEach.always(async (t) => {
});
});

// test('returns the default greeting', async (t) => {
// const { contract } = t.context.accounts;
// const greeting: string = await contract.view('get_greeting', {});
// t.is(greeting, 'Hello');
// });
test('returns the number of handled amount', async (t) => {
const { contract } = t.context.accounts;
const amount: string = await contract.view('get_handled_amount', {});
t.is(amount, '0');
});

test('returns the number of jobs', async (t) => {
const { contract } = t.context.accounts;
const amount: number = await contract.view('get_number_of_jobs', {});
t.is(amount, 0);
});

// test('changes the greeting', async (t) => {
// const { root, contract } = t.context.accounts;
Expand Down
3 changes: 2 additions & 1 deletion dqpu-contract/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { NearBindgen, near, call, view, UnorderedMap, assert } from 'near-sdk-js';
import { NearBindgen, near, call, view, UnorderedMap, assert, initialize } from 'near-sdk-js';
import { AccountId } from 'near-sdk-js/lib/types';
import { Job, JobStatus } from './model';

Expand All @@ -24,6 +24,7 @@ class DQPU {
latest_jid: bigint = BigInt(0);
money_handled: bigint = BigInt(0);

@initialize({ privateFunction: true })
init() {
this.owner = near.predecessorAccountId();
this.verifiers.set(this.owner, this.owner);
Expand Down

0 comments on commit 869ec2d

Please sign in to comment.