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.
70 lines
2.7 KiB
70 lines
2.7 KiB
import chai, {assert, expect} from "chai"; |
|
import chaiBN from "chai-bn"; |
|
import BN from "bn.js"; |
|
|
|
chai.use(chaiBN(BN)); |
|
|
|
import {Address, beginCell, Builder, Cell, contractAddress, parseDict, parseDictBitString, 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, sha256} from "ton-crypto"; |
|
import {signBuy} from "../contracts/main"; |
|
import {Base64} from "@tonconnect/protocol"; |
|
|
|
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: "levcccc", ownerAddr}), |
|
value: new BN(0), |
|
}); |
|
const res = await contract.sendInternalMessage(initializeMsg); |
|
|
|
// 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"}), |
|
value: new BN(0), |
|
}) |
|
const res2 = await contract.sendInternalMessage(setDataMsg); |
|
expect(res2.type).to.equal("success"); |
|
expect(res2.exit_code).to.equal(0); |
|
let nft_data = await contract.invokeGetMethod("get_nft_data", []); |
|
console.log('res4', nft_data.result[4]); |
|
// @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"); |
|
}); |
|
});
|
|
|