Browse Source

Tests for the item

master
Lev 2 years ago
parent
commit
e3291e9be5
  1. 37
      contracts/main.ts
  2. 13
      contracts/nft-item.fc
  3. 2
      test/creation.spec.ts
  4. 53
      test/item.spec.ts
  5. 4
      test/signing.spec.ts

37
contracts/main.ts

@ -60,6 +60,29 @@ export function collectionData(params: {
.endCell(); .endCell();
} }
export function itemDataUninit(params: { domain: String, collectionAddress: Address }): Cell {
let domain = params.domain.split('.')[0];
let index = new BN(hashCell(makeSnakeCell(Buffer.from(domain))));
return beginCell()
.storeUint(index, 256)
.storeAddress(params.collectionAddress).endCell();
}
export function itemData(params: {
domain: String, collectionAddress: Address,
ownerAddress: Address }): Cell {
let domain = params.domain.split('.')[0];
let zone = params.domain.split('.').slice(1).join('.');
let index = new BN(hashCell(makeSnakeCell(Buffer.from(domain))));
return beginCell()
.storeUint(index, 256)
.storeAddress(params.collectionAddress)
.storeAddress(params.ownerAddress)
.storeRef(itemContent(domain, zone))
.storeRef(makeSnakeCell(Buffer.from(domain)))
.storeUint(0, 64).endCell();
}
export function auctionWithWinner(winnerAddress: Address) { export function auctionWithWinner(winnerAddress: Address) {
return beginCell().storeAddress(winnerAddress).storeCoins(0).storeUint(0, 64) return beginCell().storeAddress(winnerAddress).storeCoins(0).storeUint(0, 64)
} }
@ -134,10 +157,22 @@ export function createItem(params: { domain: String, signature?: String }): Cell
.endCell(); .endCell();
} }
export function initializeItemMsg(params: { domain: String, ownerAddr: Address }): Cell {
return beginCell()
.storeAddress(params.ownerAddr)
.storeRef(makeSnakeCell(Buffer.from(params.domain)))
.endCell();
}
function itemContent(domain: string, zone: string): Cell {
return encodeOffChainContent(`https://api.agorata.io/data/${zone}/${domain}.json`)
}
export function setContent(params: { domain: string, zone: string }) { export function setContent(params: { domain: string, zone: string }) {
return beginCell() return beginCell()
.storeUint(0x1a0b9d51 , 32) .storeUint(0x1a0b9d51 , 32)
.storeRef(encodeOffChainContent(`https://api.agorata.io/data/${params.zone}/${params.domain}.json`)) .storeUint(0, 64)
.storeRef(itemContent(params.domain, params.zone))
.endCell(); .endCell();
} }

13
contracts/nft-item.fc

@ -174,19 +174,6 @@ int min_tons_for_storage() asm "1000000000 PUSHINT"; ;; 1 TON
} }
return (); return ();
} }
if (op == op::dns_balance_release) { ;; release domain
throw_unless(414, (now() - last_fill_up_time > one_year));
int min_price = get_min_price(domain.begin_parse().slice_bits(), now());
throw_unless(407, msg_value >= min_price);
int balance_without_msg = my_balance - msg_value;
int amount_to_send = balance_without_msg - min_tons_for_storage();
if (amount_to_send > 0) {
send_msg(owner_address, amount_to_send, op::dns_balance_release, query_id, null(), 2); ;; ignore errors
}
owner_address = zero_address();
store_data(index, collection_address, owner_address, content, domain, now());
return ();
}
if (op == op::get_static_data()) { if (op == op::get_static_data()) {
send_msg(sender_address, 0, op::report_static_data(), query_id, begin_cell().store_uint(index, 256).store_slice(collection_address), 64); ;; carry all the remaining value of the inbound message send_msg(sender_address, 0, op::report_static_data(), query_id, begin_cell().store_uint(index, 256).store_slice(collection_address), 64); ;; carry all the remaining value of the inbound message
return (); return ();

2
test/creation.spec.ts

@ -47,7 +47,7 @@ describe("Creating items tests", () => {
const sendToSelfMessage = internalMessage({ const sendToSelfMessage = internalMessage({
from: ownerAddr, from: ownerAddr,
body: main.createItem({ domain: "test" }), body: main.createItem({ domain: "test" }),
value: new BN(10 * main.TON()), value: new BN(main.TON() / 100),
}); });
const res = await contract.sendInternalMessage(sendToSelfMessage); const res = await contract.sendInternalMessage(sendToSelfMessage);
expect(res.type).to.equal("failed"); expect(res.type).to.equal("failed");

53
test/item.spec.ts

@ -0,0 +1,53 @@
import chai, {assert, expect} from "chai";
import chaiBN from "chai-bn";
import BN from "bn.js";
chai.use(chaiBN(BN));
import {Address, Builder, Cell, contractAddress, Slice} from "ton";
import {runContract, SmartContract} from "ton-contract-executor";
import * as main from "../contracts/main";
import {internalMessage, randomAddress} from "./helpers";
import {hex as item_code} from "../build/nft-item.compiled.json";
import {makeSnakeCell} from "../contracts/utils";
import {keyPairFromSeed, KeyPair, sign, keyPairFromSecretKey} from "ton-crypto";
import {signBuy} from "../contracts/main";
let data = main.itemDataUninit({domain: "test", collectionAddress: randomAddress("collection")});
describe("Creating items tests", () => {
let contract: SmartContract;
let debug: boolean = true;
beforeEach(async () => {
contract = await SmartContract.fromCell(
Cell.fromBoc(item_code)[0],
data,
{debug: debug}
);
contract.setC7Config({
myself: randomAddress("item")
})
});
it("allows to set the data", async () => {
let ownerAddr = randomAddress("dude");
const initializeMsg = internalMessage({
from: randomAddress("collection"),
body: main.initializeItemMsg({domain: "test", ownerAddr}),
value: new BN(0),
});
const res = await contract.sendInternalMessage(initializeMsg);
expect(res.type).to.equal("success");
expect(res.exit_code).to.equal(0);
const setDataMsg = internalMessage({
from: ownerAddr,
body: main.setContent({domain: "test", zone: "example.ton"}),
value: new BN(0),
})
const res2 = await contract.sendInternalMessage(setDataMsg);
expect(res2.type).to.equal("success");
expect(res2.exit_code).to.equal(0);
});
});

4
test/signing.spec.ts

@ -49,8 +49,8 @@ describe("Creating items tests", () => {
}); });
const res = await contract.sendInternalMessage(sendToSelfMessage); const res = await contract.sendInternalMessage(sendToSelfMessage);
// console.log(res); // console.log(res);
let fs = require('fs'); // let fs = require('fs');
fs.writeFile('logs.txt', res.logs, (_: any) => {}); // fs.writeFile('logs.txt', res.logs, (_: any) => {});
expect(res.type).to.equal("success"); expect(res.type).to.equal("success");
expect(res.exit_code).to.equal(0); expect(res.exit_code).to.equal(0);
}); });

Loading…
Cancel
Save