Skip to content

Contract composability #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions examples/__tests__/test-counter.ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,31 @@ test.beforeEach(async (t) => {
// Prepare sandbox for tests, create accounts, deploy contracts, etc.
const root = worker.rootAccount;

let counterContract;

switch (process.env.COUNTER_CONTRACT_TYPE) {
case "COUNTER_LOW_LEVEL": {
counterContract = "./build/counter-lowlevel.wasm";
break;
}
case "COUNTER_TS": {
counterContract = "./build/counter-ts.wasm";
break;
}
case "COUNTER_JS": {
counterContract = "./build/counter.wasm";
break;
}
case "COUNTER_EXTENDED": {
counterContract = "./build/counter-extended.wasm";
break;
}
default:
throw Error("Unknown COUNTER_CONTRACT_TYPE");
}

// Deploy the counter contract.
const counter = await root.devDeploy(
process.env["COUNTER_LOWLEVEL"]
? "./build/counter-lowlevel.wasm"
: process.env["COUNTER_TS"]
? "./build/counter-ts.wasm"
: "./build/counter.wasm"
);
const counter = await root.devDeploy(counterContract);

// Test users
const ali = await root.createSubAccount("ali");
Expand Down
8 changes: 5 additions & 3 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"build:counter": "near-sdk-js build src/counter.js build/counter.wasm",
"build:counter-lowlevel": "near-sdk-js build src/counter-lowlevel.js build/counter-lowlevel.wasm",
"build:counter-ts": "near-sdk-js build src/counter.ts build/counter-ts.wasm",
"build:counter-extended": "near-sdk-js build src/counter-extended.ts build/counter-extended.wasm",
"build:cross-contract-call": "near-sdk-js build src/status-message.js build/status-message.wasm && near-sdk-js build src/cross-contract-call.js build/cross-contract-call.wasm",
"build:cross-contract-call-loop": "near-sdk-js build src/counter.js build/counter.wasm && near-sdk-js build src/cross-contract-call-loop.js build/cross-contract-call-loop.wasm",
"build:fungible-token-lockable": "near-sdk-js build src/fungible-token-lockable.js build/fungible-token-lockable.wasm",
Expand All @@ -28,9 +29,10 @@
"test:nft": "ava __tests__/standard-nft/*",
"test:status-message": "ava __tests__/test-status-message.ava.js",
"test:clean-state": "ava __tests__/test-clean-state.ava.js",
"test:counter": "ava __tests__/test-counter.ava.js",
"test:counter-lowlevel": "COUNTER_LOWLEVEL=1 ava __tests__/test-counter.ava.js",
"test:counter-ts": "COUNTER_TS=1 ava __tests__/test-counter.ava.js",
"test:counter": "COUNTER_CONTRACT_TYPE=COUNTER_JS ava __tests__/test-counter.ava.js",
"test:counter-lowlevel": "COUNTER_CONTRACT_TYPE=COUNTER_LOW_LEVEL ava __tests__/test-counter.ava.js",
"test:counter-ts": "COUNTER_CONTRACT_TYPE=COUNTER_TS ava __tests__/test-counter.ava.js",
"test:counter-extended": "COUNTER_CONTRACT_TYPE=COUNTER_EXTENDED ava __tests__/test-counter.ava.js",
"test:cross-contract-call": "ava __tests__/test-cross-contract-call.ava.js",
"test:cross-contract-call-loop": "ava __tests__/test-cross-contract-call-loop.ava.js",
"test:fungible-token-lockable": "ava __tests__/test-fungible-token-lockable.ava.js",
Expand Down
11 changes: 11 additions & 0 deletions examples/src/couter-extended.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { near, NearBindgen, call } from "near-sdk-js";
import { Counter } from "./counter";

@NearBindgen({})
export class CounterWithReset extends Counter {
@call({})
reset() {
this.count = 0;
near.log(`Counter is set to 0`);
}
}