Browse Source

Fixed content, removed old tests

master
Lev 2 years ago
parent
commit
8e94348531
  1. 19
      build/cli.js
  2. 2
      build/minter.deploy.ts
  3. 4
      contracts/main.ts
  4. 46
      test/counter.spec.ts
  5. 85
      test/deposit.spec.ts
  6. 54
      test/ownership.spec.ts

19
build/cli.js

@ -25,6 +25,25 @@ let commands = [
body: main.depositMsg((parseFloat(args._[1]) * main.TON()))
})
}
},
{
name: 'withdraw',
options: [
{
name: 'minter',
help: 'The jetton address'
},
{
name: "amount"
}
],
command: async function withdraw(args) {
let [walletContract, walletKey] = await getWallet();
await sendInternalMessageWithWallet({
walletContract, secretKey: walletKey.secretKey, value: 0.15 * main.TON(), to: Address.parse(args._[0]),
body: main.withdrawMsg((parseFloat(args._[1]) * main.TON()))
})
}
}
]

2
build/minter.deploy.ts

@ -8,7 +8,7 @@ export function minterParams() {
return {
adminAddress: Address.parse("EQD7zbEMaWC2yMgSJXmIF7HbLr1yuBo2GnZF_CJNkUiGSe32"),
supply: 0,
content: encodeOffChainContent(""),
content: encodeOffChainContent("https://files.ennucore.com/bton.json"),
wallet_code: Cell.fromBoc(walletCode)[0],
};
}

4
contracts/main.ts

@ -79,8 +79,8 @@ export function depositMsg(amount: number): Cell {
.storeUint(0, 64).storeCoins(amount).endCell();
}
export function withdrawMsg(params: { withdrawAmount: BN }): Cell {
return beginCell().storeUint(0x47d1895f, 32).storeUint(0, 64).storeCoins(params.withdrawAmount).endCell();
export function withdrawMsg(amount: BN | number): Cell {
return beginCell().storeUint(0x47d1895f, 32).storeUint(0, 64).storeCoins(amount).endCell();
}
export async function getWallet(isTestnet: boolean = true) {

46
test/counter.spec.ts

@ -1,46 +0,0 @@
import chai, { expect } from "chai";
import chaiBN from "chai-bn";
import BN from "bn.js";
chai.use(chaiBN(BN));
import { Cell } from "ton";
import { SmartContract } from "ton-contract-executor";
import * as main from "../contracts/main";
import { internalMessage, randomAddress } from "./helpers";
import { hex } from "../build/main.compiled.json";
describe("Counter tests", () => {
let contract: SmartContract;
beforeEach(async () => {
contract = await SmartContract.fromCell(
Cell.fromBoc(hex)[0], // code cell from build output
main.data({
ownerAddress: randomAddress("owner"),
counter: 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 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("notowner"),
body: main.increment(),
})
);
expect(send.type).to.equal("success");
const call2 = await contract.invokeGetMethod("counter", []);
expect(call2.result[0]).to.be.bignumber.equal(new BN(18));
});
});

85
test/deposit.spec.ts

@ -1,85 +0,0 @@
import chai, { expect } from "chai";
import chaiBN from "chai-bn";
import BN from "bn.js";
chai.use(chaiBN(BN));
import { Cell, toNano } from "ton";
import { SmartContract } from "ton-contract-executor";
import * as main from "../contracts/main";
import { internalMessage, randomAddress, setBalance } from "./helpers";
import { hex } from "../build/main.compiled.json";
describe("Deposit and withdraw tests", () => {
let contract: SmartContract;
beforeEach(async () => {
contract = await SmartContract.fromCell(
Cell.fromBoc(hex)[0], // code cell from build output
main.data({
ownerAddress: randomAddress("owner"),
counter: 17,
})
);
});
it("should get balance", async () => {
setBalance(contract, toNano(37));
const call = await contract.invokeGetMethod("balance", []);
expect(call.result[0]).to.be.bignumber.equal(toNano(37));
});
it("should allow the owner to withdraw when balance is high", async () => {
setBalance(contract, toNano(37));
const send = await contract.sendInternalMessage(
internalMessage({
from: randomAddress("owner"),
body: main.withdraw({ withdrawAmount: toNano(20) }),
})
);
expect(send.type).to.equal("success");
expect(send.actionList).to.have.lengthOf(1);
const resultMessage = (send.actionList[0] as any)?.message?.info;
expect(resultMessage?.dest?.equals(randomAddress("owner"))).to.equal(true);
expect(resultMessage?.value?.coins).to.be.bignumber.equal(toNano(20));
});
it("should prevent others from withdrawing when balance is high", async () => {
setBalance(contract, toNano(37));
const send = await contract.sendInternalMessage(
internalMessage({
from: randomAddress("notowner"),
body: main.withdraw({ withdrawAmount: toNano(20) }),
})
);
expect(send.type).to.equal("failed");
expect(send.exit_code).to.equal(102); // access_denied in contracts/imports/constants.fc
});
it("should prevent the owner to withdraw when balance is low", async () => {
setBalance(contract, toNano(10));
const send = await contract.sendInternalMessage(
internalMessage({
from: randomAddress("owner"),
body: main.withdraw({ withdrawAmount: toNano(20) }),
})
);
expect(send.type).to.equal("failed");
expect(send.exit_code).to.equal(103); // insufficient_balance in contracts/imports/constants.fc
});
it("should leave enough balance for rent", async () => {
setBalance(contract, toNano(20));
const send = await contract.sendInternalMessage(
internalMessage({
from: randomAddress("owner"),
body: main.withdraw({ withdrawAmount: toNano(20) }),
})
);
expect(send.type).to.equal("success");
expect(send.actionList).to.have.lengthOf(1);
const resultMessage = (send.actionList[0] as any)?.message?.info;
expect(resultMessage?.dest?.equals(randomAddress("owner"))).to.equal(true);
expect(resultMessage?.value?.coins).to.be.bignumber.equal(toNano(20).sub(toNano(0.01))); // min_tons_for_storage in contracts/imports/constants.fc
});
});

54
test/ownership.spec.ts

@ -1,54 +0,0 @@
import chai, { expect } from "chai";
import chaiBN from "chai-bn";
import BN from "bn.js";
chai.use(chaiBN(BN));
import { Cell, Slice } from "ton";
import { SmartContract } from "ton-contract-executor";
import * as main from "../contracts/main";
import { internalMessage, randomAddress } from "./helpers";
import { hex } from "../build/main.compiled.json";
describe("Transfer ownership tests", () => {
let contract: SmartContract;
beforeEach(async () => {
contract = await SmartContract.fromCell(
Cell.fromBoc(hex)[0], // code cell from build output
main.data({
ownerAddress: randomAddress("owner"),
counter: 17,
})
);
});
it("should allow the owner to change owners", async () => {
const send = await contract.sendInternalMessage(
internalMessage({
from: randomAddress("owner"),
body: main.transferOwnership({ newOwnerAddress: randomAddress("newowner") }),
})
);
expect(send.type).to.equal("success");
const call = await contract.invokeGetMethod("owner_address", []);
const address = (call.result[0] as Slice).readAddress();
expect(address?.equals(randomAddress("newowner"))).to.equal(true);
});
it("should prevent others from changing owners", async () => {
const send = await contract.sendInternalMessage(
internalMessage({
from: randomAddress("notowner"),
body: main.transferOwnership({ newOwnerAddress: randomAddress("newowner") }),
})
);
expect(send.type).to.equal("failed");
expect(send.exit_code).to.equal(102); // access_denied in contracts/imports/constants.fc
const call = await contract.invokeGetMethod("owner_address", []);
const address = (call.result[0] as Slice).readAddress();
expect(address?.equals(randomAddress("owner"))).to.equal(true);
});
});
Loading…
Cancel
Save