From 8e9434853136e33ec9fa2ff1707770227f116084 Mon Sep 17 00:00:00 2001 From: ennucore Date: Wed, 18 Jan 2023 14:06:48 +0100 Subject: [PATCH] Fixed content, removed old tests --- build/cli.js | 19 ++++++++++ build/minter.deploy.ts | 2 +- contracts/main.ts | 4 +- test/counter.spec.ts | 46 ----------------------- test/deposit.spec.ts | 85 ------------------------------------------ test/ownership.spec.ts | 54 --------------------------- 6 files changed, 22 insertions(+), 188 deletions(-) delete mode 100644 test/counter.spec.ts delete mode 100644 test/deposit.spec.ts delete mode 100644 test/ownership.spec.ts diff --git a/build/cli.js b/build/cli.js index d066014..40ae081 100644 --- a/build/cli.js +++ b/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())) + }) + } } ] diff --git a/build/minter.deploy.ts b/build/minter.deploy.ts index a7789aa..5f7f9d3 100644 --- a/build/minter.deploy.ts +++ b/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], }; } diff --git a/contracts/main.ts b/contracts/main.ts index c3c2fcc..1666ea5 100644 --- a/contracts/main.ts +++ b/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) { diff --git a/test/counter.spec.ts b/test/counter.spec.ts deleted file mode 100644 index c58a612..0000000 --- a/test/counter.spec.ts +++ /dev/null @@ -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)); - }); -}); diff --git a/test/deposit.spec.ts b/test/deposit.spec.ts deleted file mode 100644 index 1505982..0000000 --- a/test/deposit.spec.ts +++ /dev/null @@ -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 - }); -}); diff --git a/test/ownership.spec.ts b/test/ownership.spec.ts deleted file mode 100644 index b6e18c6..0000000 --- a/test/ownership.spec.ts +++ /dev/null @@ -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); - }); -});