|
|
|
import chai, { assert, expect } from "chai";
|
|
|
|
import chaiBN from "chai-bn";
|
|
|
|
import BN from "bn.js";
|
|
|
|
chai.use(chaiBN(BN));
|
|
|
|
|
|
|
|
import { Builder, 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/nft-collection.compiled.json";
|
|
|
|
import {hex as item_code} from "../build/nft-item.compiled.json";
|
|
|
|
import {makeSnakeCell} from "../contracts/utils";
|
|
|
|
|
|
|
|
describe("Creating items tests", () => {
|
|
|
|
let contract: SmartContract;
|
|
|
|
let debug: boolean = false;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
contract = await SmartContract.fromCell(
|
|
|
|
Cell.fromBoc(hex)[0],
|
|
|
|
main.collectionData({
|
|
|
|
ownerAddress: randomAddress("owner"),
|
|
|
|
code: Cell.fromBoc(item_code)[0],
|
|
|
|
ownerKey: 0,
|
|
|
|
}),
|
|
|
|
{ debug: debug }
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows to buy an item", async () => {
|
|
|
|
main.setContractBalance(contract, 10 * main.TON());
|
|
|
|
let ownerAddr = randomAddress("owner");
|
|
|
|
const sendToSelfMessage = internalMessage({
|
|
|
|
from: ownerAddr,
|
|
|
|
body: main.createItem({ domain: "test" }),
|
|
|
|
value: new BN(100 * main.TON()),
|
|
|
|
});
|
|
|
|
const res = await contract.sendInternalMessage(sendToSelfMessage);
|
|
|
|
|
|
|
|
expect(res.type).to.equal("success");
|
|
|
|
expect(res.exit_code).to.equal(0);
|
|
|
|
});
|
|
|
|
it("does not allow to buy an item if the price is too low", async () => {
|
|
|
|
main.setContractBalance(contract, 10 * main.TON());
|
|
|
|
let ownerAddr = randomAddress("owner");
|
|
|
|
const sendToSelfMessage = internalMessage({
|
|
|
|
from: ownerAddr,
|
|
|
|
body: main.createItem({ domain: "test" }),
|
|
|
|
value: new BN(main.TON() / 100),
|
|
|
|
});
|
|
|
|
const res = await contract.sendInternalMessage(sendToSelfMessage);
|
|
|
|
expect(res.type).to.equal("failed");
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|