TON contracts for Agorata
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.8 KiB

import chai, {assert, expect} from "chai";
import chaiBN from "chai-bn";
import BN from "bn.js";
chai.use(chaiBN(BN));
2 years ago
import {Address, beginCell, Builder, Cell, contractAddress, parseDict, parseDictBitString, Slice, toNano} 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, sha256} from "ton-crypto";
import {signBuy} from "../contracts/main";
import {Base64} from "@tonconnect/protocol";
let data = main.itemDataUninit({domain: "test", collectionAddress: randomAddress("collection")});
2 years ago
describe("Creating item tests", () => {
let contract: SmartContract;
let debug: boolean = true;
beforeEach(async () => {
contract = await SmartContract.fromCell(
Cell.fromBoc(item_code)[0],
data,
{debug: debug}
);
contract.setC7Config({
2 years ago
myself: randomAddress("item"),
balance: toNano(1).toNumber(),
})
});
it("allows to set the data", async () => {
let ownerAddr = randomAddress("dude");
const initializeMsg = internalMessage({
from: randomAddress("collection"),
body: main.initializeItemMsg({domain: "levcccc", ownerAddr, zone: "example.ton"}),
value: new BN(0),
});
const res = await contract.sendInternalMessage(initializeMsg);
2 years ago
// let nft_data = await contract.invokeGetMethod("get_nft_data", []);
// console.log(nft_data.result);
expect(res.type).to.equal("success");
expect(res.exit_code).to.equal(0);
const setDataMsg = internalMessage({
from: ownerAddr,
body: await main.setContent({domain: "levcccc", zone: "example.ton"}),
2 years ago
value: new BN(toNano(2)),
})
const res2 = await contract.sendInternalMessage(setDataMsg);
expect(res2.type).to.equal("success");
expect(res2.exit_code).to.equal(0);
2 years ago
let nft_data = await contract.invokeGetMethod("get_nft_data", []);
console.log('res4', nft_data.result[4]);
2 years ago
// @ts-ignore
console.log(Base64.encode((nft_data.result[4] as Cell).toBoc()))
// @ts-ignore
// let content = (nft_data.result[4] as Cell).beginParse();
// let a = parseDict(content, 256, (s) => s);
// console.log(a);
let resolved = (await contract.invokeGetMethod("dnsresolve", [
{type: "cell_slice", value: "te6cckEBAQEAAwAAAgDTZ9xB"},
{type: "int", value: new BN(await sha256('uri')).toString()}
]));
expect(resolved.type).to.equal("success");
});
});