|
|
|
@ -1,7 +1,11 @@
|
|
|
|
|
import { expect } from "chai"; |
|
|
|
|
import chai, { expect } from "chai"; |
|
|
|
|
import chaiBN from "chai-bn"; |
|
|
|
|
import BN from "bn.js"; |
|
|
|
|
chai.use(chaiBN(BN)); |
|
|
|
|
|
|
|
|
|
import { SmartContract } from "ton-contract-executor"; |
|
|
|
|
import { createCode, createData } from "../contracts/main"; |
|
|
|
|
import { randomAddress } from "./utils"; |
|
|
|
|
import { createCode, createData, op_increment } from "../contracts/main"; |
|
|
|
|
import { internalMessage, randomAddress } from "./utils"; |
|
|
|
|
|
|
|
|
|
describe("Counter tests", () => { |
|
|
|
|
let contract: SmartContract; |
|
|
|
@ -10,19 +14,30 @@ describe("Counter tests", () => {
|
|
|
|
|
contract = await SmartContract.fromCell( |
|
|
|
|
createCode(), |
|
|
|
|
createData({ |
|
|
|
|
ownerAddress: randomAddress(0, "seed1"), |
|
|
|
|
ownerAddress: randomAddress(0, "owner"), |
|
|
|
|
counter: 17, |
|
|
|
|
}) |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("should run getter counter() and get counter value", async () => { |
|
|
|
|
const call = await contract.invokeGetMethod("counter", []); |
|
|
|
|
expect(call.result[0].toNumber()).to.equal(17); |
|
|
|
|
it("should get the meaning of life", async () => { |
|
|
|
|
const call = await contract.invokeGetMethod("meaning_of_life", []); |
|
|
|
|
expect(call.result[0]).to.be.bignumber.equal(new BN(42)); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("should run getter meaning_of_life()", async () => { |
|
|
|
|
const call = await contract.invokeGetMethod("meaning_of_life", []); |
|
|
|
|
expect(call.result[0].toNumber()).to.equal(42); |
|
|
|
|
it("should get counter value and increment it", async () => { |
|
|
|
|
const call = await contract.invokeGetMethod("counter", []); |
|
|
|
|
expect(call.result[0]).to.be.bignumber.equal(new BN(17)); |
|
|
|
|
|
|
|
|
|
const send = await contract.sendInternalMessage( |
|
|
|
|
internalMessage({ |
|
|
|
|
from: randomAddress(0, "notowner"), |
|
|
|
|
body: op_increment(), |
|
|
|
|
}) |
|
|
|
|
); |
|
|
|
|
expect(send.type).to.equal("success"); |
|
|
|
|
|
|
|
|
|
const call2 = await contract.invokeGetMethod("counter", []); |
|
|
|
|
expect(call2.result[0]).to.be.bignumber.equal(new BN(18)); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|