-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into daniyar/abi-gen
- Loading branch information
Showing
38 changed files
with
723 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Worker, NEAR } from "near-workspaces"; | ||
import test from "ava"; | ||
|
||
test.beforeEach(async (t) => { | ||
const worker = await Worker.init(); | ||
const root = worker.rootAccount; | ||
|
||
const xccLoop = await root.createSubAccount("xcc-loop"); | ||
await xccLoop.deploy("./build/cross-contract-call-loop.wasm"); | ||
|
||
const firstContract = await root.createSubAccount("first-contract"); | ||
const secondContract = await root.createSubAccount("second-contract"); | ||
const thirdContract = await root.createSubAccount("third-contract"); | ||
await firstContract.deploy("./build/counter.wasm"); | ||
await secondContract.deploy("./build/counter.wasm"); | ||
await thirdContract.deploy("./build/counter.wasm"); | ||
|
||
await root.call(firstContract, "increase", {}); | ||
await root.call(secondContract, "increase", {}); | ||
await root.call(thirdContract, "increase", {}); | ||
|
||
const alice = await root.createSubAccount("alice", { | ||
initialBalance: NEAR.parse("100 N").toJSON(), | ||
}); | ||
|
||
t.context.worker = worker; | ||
t.context.accounts = { root, alice, xccLoop }; | ||
}); | ||
|
||
test.afterEach.always(async (t) => { | ||
await t.context.worker.tearDown().catch((error) => { | ||
console.log("Failed to tear down the worker:", error); | ||
}); | ||
}); | ||
|
||
test("should have a count of 3 after calling incrementCount", async (t) => { | ||
const { xccLoop, alice } = t.context.accounts; | ||
const expected = 3; | ||
const callbackResult = await alice.call( | ||
xccLoop, | ||
"incrementCount", | ||
{}, | ||
{ gas: "300" + "0".repeat(12) } | ||
); | ||
t.is(callbackResult, 3); | ||
const result = await xccLoop.view("getCount"); | ||
t.deepEqual(result, expected); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Worker } from "near-workspaces"; | ||
import test from "ava"; | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
|
||
test.beforeEach(async (t) => { | ||
const worker = await Worker.init(); | ||
const root = worker.rootAccount; | ||
|
||
const ali = await root.createSubAccount("ali"); | ||
|
||
const contract = await root.devDeploy( | ||
"build/programmatic-update-before.wasm" | ||
); | ||
|
||
await contract.call(contract, "init", { manager: ali.accountId }); | ||
|
||
t.context.worker = worker; | ||
t.context.accounts = { root, contract, ali }; | ||
}); | ||
|
||
test.afterEach.always(async (t) => { | ||
await t.context.worker.tearDown().catch((error) => { | ||
console.log("Failed to tear down the worker:", error); | ||
}); | ||
}); | ||
|
||
test("the contract can be programmatically updated", async (t) => { | ||
const { ali, contract } = t.context.accounts; | ||
|
||
// ASSERT BEFORE CODE UPDATE | ||
const codeBefore = await contract.viewCodeRaw(); | ||
const beforeDefaultGreeting = await contract.view("get_greeting", {}); | ||
t.is(beforeDefaultGreeting, "Hello"); | ||
|
||
// ACT (UPDATE CODE) | ||
const code = fs.readFileSync( | ||
path.resolve("./build/programmatic-update-after.wasm") | ||
); | ||
await ali.call(contract, "updateContract", code, { | ||
gas: "300" + "0".repeat(12), // 300 Tgas | ||
}); | ||
|
||
// ASSERT AFTER CODE UPDATE | ||
const codeAfter = await contract.viewCodeRaw(); | ||
const afterDefaultGreeting = await contract.view("view_greeting", {}); | ||
t.not(codeBefore, codeAfter, "code should be different after update"); | ||
t.is(afterDefaultGreeting, "Hi"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.