2019-06-14 04:36:27 +00:00
|
|
|
const EmbarkJS = require('Embark/EmbarkJS');
|
2019-06-05 17:35:01 +00:00
|
|
|
const Utils = require('../utils/testUtils');
|
|
|
|
const MiniMeToken = require('Embark/contracts/MiniMeToken');
|
|
|
|
const TestStatusNetwork = require('Embark/contracts/TestStatusNetwork');
|
|
|
|
const StickerMarket = require('Embark/contracts/StickerMarket');
|
2019-06-14 04:36:27 +00:00
|
|
|
const StickerPack = require('Embark/contracts/StickerPack');
|
|
|
|
const StickerType = require('Embark/contracts/StickerType');
|
2019-06-05 17:35:01 +00:00
|
|
|
const StickerMarketMigrated = require('Embark/contracts/StickerMarketMigrated');
|
|
|
|
|
|
|
|
config({
|
|
|
|
contracts: {
|
|
|
|
"MiniMeTokenFactory": {},
|
|
|
|
"MiniMeToken": {
|
|
|
|
"args":["$MiniMeTokenFactory", "0x0", "0x0", "Status Test Token", 18, "STT", true],
|
|
|
|
},
|
|
|
|
"TestStatusNetwork": {
|
|
|
|
"args": ["0x0", "$MiniMeToken"],
|
|
|
|
"onDeploy": [
|
|
|
|
"await MiniMeToken.methods.changeController(TestStatusNetwork.address).send()",
|
|
|
|
"await TestStatusNetwork.methods.setOpen(true).send()",
|
|
|
|
]
|
|
|
|
},
|
2019-06-14 06:14:28 +00:00
|
|
|
"StickerPack": {
|
|
|
|
"args": []
|
|
|
|
},
|
|
|
|
"StickerType": {
|
|
|
|
"args": []
|
|
|
|
},
|
2019-06-05 17:35:01 +00:00
|
|
|
"StickerMarket": {
|
2019-06-14 06:14:28 +00:00
|
|
|
"args": ["$MiniMeToken", "$StickerPack", "$StickerType"],
|
|
|
|
"onDeploy": [
|
|
|
|
"await StickerPack.methods.changeController(StickerMarket.address).send()",
|
|
|
|
"await StickerType.methods.changeController(StickerMarket.address).send()",
|
|
|
|
]
|
2019-06-05 17:35:01 +00:00
|
|
|
},
|
|
|
|
"StickerMarketMigrated": {
|
2019-06-14 04:36:27 +00:00
|
|
|
"args": ["$StickerMarket"]
|
2019-06-05 17:35:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
contract("StickerMarket", function() {
|
|
|
|
this.timeout(0);
|
|
|
|
var accounts;
|
|
|
|
var testPacks;
|
2019-06-14 04:36:27 +00:00
|
|
|
var stickerPack;
|
|
|
|
var stickerType;
|
|
|
|
var registerFee = "0";
|
2019-06-05 17:35:01 +00:00
|
|
|
let registeredPacks = [];
|
|
|
|
|
2019-06-14 04:36:27 +00:00
|
|
|
before(async function() {
|
|
|
|
accounts = await web3.eth.getAccounts();
|
|
|
|
stickerPack = new EmbarkJS.Blockchain.Contract({
|
|
|
|
abi: StickerPack._jsonInterface,
|
|
|
|
address: await StickerMarket.methods.stickerPack().call()
|
|
|
|
});
|
|
|
|
stickerType = new EmbarkJS.Blockchain.Contract({
|
|
|
|
abi: StickerType._jsonInterface,
|
|
|
|
address: await StickerMarket.methods.stickerType().call()
|
2019-06-05 17:35:01 +00:00
|
|
|
});
|
2019-06-14 04:36:27 +00:00
|
|
|
testPacks = [
|
|
|
|
{
|
|
|
|
category: ["0x00000000", "0x00000001","0x00000002","0x00000003","0x00000004"],
|
|
|
|
price: "10000000000000000000",
|
|
|
|
donate: "0",
|
|
|
|
contentHash:"0x55c72bf3b3d468c7c36c848a4d49bb11101dc79bc2f6484bf1ef796fc498919a",
|
|
|
|
owner: accounts[1]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: ["0x00000000", "0x00000001"],
|
|
|
|
price: "10000000000000000000",
|
|
|
|
donate: "10",
|
|
|
|
contentHash:"0xe434491f185cedfea522bd0b937ce849906833aefa20a76e8e50db194baf34cb",
|
|
|
|
owner: accounts[2]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: ["0x00000000", "0x00000001","0x00000002","0x00000004"],
|
|
|
|
price: "10000000000000000000",
|
|
|
|
donate: "100",
|
|
|
|
contentHash:"0xf4c247e858aba2942bf0ed6008c15a387c88c262c70f930ab91799655d71367d",
|
|
|
|
owner: accounts[3]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: ["0x00000000", "0x00000002","0x00000003","0x00000004"],
|
|
|
|
price: "10000000000000000000",
|
|
|
|
donate: "1000",
|
|
|
|
contentHash:"0x66c2aec914d17249c66a750303521a51607c38d084ae173976e54ad40473d056",
|
|
|
|
owner: accounts[4]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: ["0x00000000", "0x00000001","0x00000002","0x00000004"],
|
|
|
|
price: "10000000000000000000",
|
|
|
|
donate: "10000",
|
|
|
|
contentHash:"0x4e25277a1af127bd1c2fce6aa20ac7eae8fded9c615b7964ebe9e18779765108",
|
|
|
|
owner: accounts[5]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: ["0x00000000", "0x00000004"],
|
|
|
|
price: "10000000000000000000",
|
|
|
|
donate: "2",
|
|
|
|
contentHash:"0x659c423e40fc2b4f37ada1dda463aa4455d650d799d82e63af87ac8b714bee66",
|
|
|
|
owner: accounts[6]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: ["0x00000000", "0x00000003","0x00000004"],
|
|
|
|
price: "10000000000000000000",
|
|
|
|
donate: "20",
|
|
|
|
contentHash:"0xbbf932b8a154bc1d496ebbfa2acca571119d53a6cb5986d8a187e85ac8a37265",
|
|
|
|
owner: accounts[7]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: ["0x00000000", "0x00000003"],
|
|
|
|
price: "10000000000000000000",
|
|
|
|
donate: "200",
|
|
|
|
contentHash:"0x6dd4cbc4a86825506bf85defa071a4e6ac5d76a1b6912863ef0e289327df08d2",
|
|
|
|
owner: accounts[8]
|
|
|
|
}
|
|
|
|
];
|
2019-06-05 17:35:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should register packs", async function() {
|
2019-06-14 04:36:27 +00:00
|
|
|
|
2019-06-05 17:35:01 +00:00
|
|
|
for(let i = 0; i < testPacks.length; i++){
|
|
|
|
let pack = testPacks[i];
|
2019-06-14 04:36:27 +00:00
|
|
|
let reg = await StickerMarket.methods.registerPack(pack.price, pack.donate, pack.category, pack.owner, pack.contentHash, registerFee).send();
|
2019-06-05 17:35:01 +00:00
|
|
|
registeredPacks.push({id: reg.events.Register.returnValues.packId, data: pack})
|
|
|
|
};
|
|
|
|
for(let i = 0; i < registeredPacks.length; i++){
|
|
|
|
for(let j = 0; j < registeredPacks[i].data.category.length; j++) {
|
2019-06-14 04:36:27 +00:00
|
|
|
let r = await stickerType.methods.getAvailablePacks(registeredPacks[i].data.category[j]).call();
|
|
|
|
assert.notEqual(r.indexOf(registeredPacks[i].id), -1);
|
2019-06-05 17:35:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should mint packs", async function() {
|
|
|
|
let burnRate = 10;
|
|
|
|
await StickerMarket.methods.setBurnRate(burnRate).send();
|
|
|
|
let packBuyer = accounts[2];
|
|
|
|
for(let i = 0; i < registeredPacks.length; i++){
|
|
|
|
await TestStatusNetwork.methods.mint(registeredPacks[i].data.price).send({from: packBuyer });
|
|
|
|
await MiniMeToken.methods.approve(StickerMarket.address, registeredPacks[i].data.price).send({from: packBuyer });
|
2019-06-12 05:05:46 +00:00
|
|
|
let buy = await StickerMarket.methods.buyToken(registeredPacks[i].id, packBuyer, registeredPacks[i].data.price).send({from: packBuyer });
|
2019-06-05 17:35:01 +00:00
|
|
|
let tokenId;
|
|
|
|
let toArtist = 0;
|
|
|
|
let donated = 0;
|
|
|
|
let burned = 0;
|
|
|
|
let burnAddress =(await MiniMeToken.methods.controller().call());
|
2019-06-14 04:36:27 +00:00
|
|
|
let controller = accounts[0];
|
|
|
|
for(let j = 0; j < buy.events.Transfer.length; j++) {
|
2019-06-05 17:35:01 +00:00
|
|
|
if(buy.events.Transfer[j].address == MiniMeToken.address){
|
|
|
|
if(buy.events.Transfer[j].returnValues.to == controller){
|
|
|
|
donated = buy.events.Transfer[j].returnValues.value;
|
|
|
|
}else if(buy.events.Transfer[j].returnValues.to == registeredPacks[i].data.owner){
|
|
|
|
toArtist = buy.events.Transfer[j].returnValues.value;
|
|
|
|
}else if(buy.events.Transfer[j].returnValues.to == burnAddress){
|
|
|
|
burned = buy.events.Transfer[j].returnValues.value;
|
|
|
|
}
|
2019-06-14 04:36:27 +00:00
|
|
|
}else if(buy.events.Transfer[j].address == stickerPack.address){
|
2019-06-05 17:35:01 +00:00
|
|
|
tokenId = buy.events.Transfer[j].returnValues.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
assert.equal(registeredPacks[i].data.price, (+toArtist + +donated + +burned))
|
|
|
|
assert.equal(burned, (registeredPacks[i].data.price * burnRate) / 10000, "Bad burn")
|
|
|
|
assert.equal(donated, ((+registeredPacks[i].data.price - burned) * registeredPacks[i].data.donate)/10000, "Bad donate")
|
|
|
|
assert.equal(toArtist, registeredPacks[i].data.price - (+donated + +burned), "Bad profit")
|
2019-06-14 04:36:27 +00:00
|
|
|
assert.equal(await stickerPack.methods.ownerOf(tokenId).call(), packBuyer, "Bad owner")
|
2019-06-05 17:35:01 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should mint packs with approveAndCall", async function() {
|
|
|
|
let burnRate = 10;
|
|
|
|
await StickerMarket.methods.setBurnRate(burnRate).send();
|
|
|
|
let packBuyer = accounts[2];
|
|
|
|
for(let i = 0; i < registeredPacks.length; i++){
|
|
|
|
|
|
|
|
await TestStatusNetwork.methods.mint(registeredPacks[i].data.price).send({from: packBuyer });
|
2019-06-12 05:05:46 +00:00
|
|
|
const buyCall = StickerMarket.methods.buyToken(registeredPacks[i].id, packBuyer, registeredPacks[i].data.price).encodeABI();
|
2019-06-05 17:35:01 +00:00
|
|
|
let buy = await MiniMeToken.methods.approveAndCall(StickerMarket.address, registeredPacks[i].data.price, buyCall).send({from: packBuyer });
|
|
|
|
let tokenId;
|
|
|
|
let toArtist = 0;
|
|
|
|
let donated = 0;
|
|
|
|
let burned = 0;
|
|
|
|
let burnAddress =(await MiniMeToken.methods.controller().call());
|
|
|
|
let controller = accounts[0];``
|
2019-06-14 04:36:27 +00:00
|
|
|
for(let j = 0; j < buy.events.Transfer.length; j++) {
|
2019-06-05 17:35:01 +00:00
|
|
|
if(buy.events.Transfer[j].address == MiniMeToken.address){
|
|
|
|
if(buy.events.Transfer[j].returnValues.to == controller){
|
|
|
|
donated = buy.events.Transfer[j].returnValues.value
|
|
|
|
}else if(buy.events.Transfer[j].returnValues.to == registeredPacks[i].data.owner){
|
|
|
|
toArtist = buy.events.Transfer[j].returnValues.value
|
|
|
|
}else if(buy.events.Transfer[j].returnValues.to == burnAddress){
|
|
|
|
burned = buy.events.Transfer[j].returnValues.value
|
|
|
|
}
|
2019-06-14 04:36:27 +00:00
|
|
|
}else if(buy.events.Transfer[j].address == stickerPack.address){
|
2019-06-05 17:35:01 +00:00
|
|
|
tokenId = buy.events.Transfer[j].returnValues.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(registeredPacks[i].data.price, (+toArtist + +donated + +burned), "Bad payment")
|
|
|
|
assert.equal(burned, (registeredPacks[i].data.price * burnRate) / 10000, "Bad burn")
|
|
|
|
assert.equal(donated, ((+registeredPacks[i].data.price - burned) * registeredPacks[i].data.donate)/10000, "Bad donate")
|
|
|
|
assert.equal(toArtist, registeredPacks[i].data.price - (+donated + +burned), "Bad profit")
|
2019-06-14 04:36:27 +00:00
|
|
|
assert.equal(await stickerPack.methods.ownerOf(tokenId).call(), packBuyer, "Bad owner")
|
2019-06-05 17:35:01 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should register pack with approveAndCall", async function() {
|
2019-06-14 04:36:27 +00:00
|
|
|
registerFee = "1000000000000000000";
|
2019-06-05 17:35:01 +00:00
|
|
|
await StickerMarket.methods.setRegisterFee(registerFee).send();
|
|
|
|
await TestStatusNetwork.methods.mint(registerFee).send();
|
|
|
|
let pack = testPacks[0];
|
2019-06-12 05:11:00 +00:00
|
|
|
let regCall = await StickerMarket.methods.registerPack(pack.price, pack.donate, pack.category, pack.owner, pack.contentHash, registerFee).encodeABI();
|
2019-06-14 04:36:27 +00:00
|
|
|
let packId = await stickerType.methods.packCount().call();
|
2019-06-05 17:35:01 +00:00
|
|
|
let reg = await MiniMeToken.methods.approveAndCall(StickerMarket.address, registerFee, regCall).send();
|
|
|
|
|
|
|
|
for(let j = 0; j < pack.category.length; j++) {
|
2019-06-14 04:36:27 +00:00
|
|
|
assert.notEqual((await stickerType.methods.getAvailablePacks(pack.category[j]).call()).indexOf(packId), -1);
|
2019-06-05 17:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await StickerMarket.methods.purgePack(packId, 0).send();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should purge packs", async function() {
|
|
|
|
var i = 0;
|
|
|
|
await StickerMarket.methods.purgePack(registeredPacks[i].id, 0).send();
|
|
|
|
for(let j = 0; j < registeredPacks[i].data.category.length; j++) {
|
2019-06-14 04:36:27 +00:00
|
|
|
assert.equal((await stickerType.methods.getAvailablePacks(registeredPacks[i].data.category[j]).call()).indexOf(registeredPacks[i].id), -1);
|
2019-06-05 17:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i = registeredPacks.length-1;
|
|
|
|
await StickerMarket.methods.purgePack(registeredPacks[i].id, 0).send();
|
|
|
|
for(let j = 0; j < registeredPacks[i].data.category.length; j++) {
|
2019-06-14 04:36:27 +00:00
|
|
|
assert.equal((await stickerType.methods.getAvailablePacks(registeredPacks[i].data.category[j]).call()).indexOf(registeredPacks[i].id), -1);
|
2019-06-05 17:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i = 2;
|
|
|
|
await StickerMarket.methods.purgePack(registeredPacks[i].id, 0).send();
|
|
|
|
for(let j = 0; j < registeredPacks[i].data.category.length; j++) {
|
2019-06-14 04:36:27 +00:00
|
|
|
assert.equal((await stickerType.methods.getAvailablePacks(registeredPacks[i].data.category[j]).call()).indexOf(registeredPacks[i].id), -1);
|
2019-06-05 17:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not mint a pack with price 0", async function() {
|
2019-06-14 04:36:27 +00:00
|
|
|
registerFee = "0";
|
|
|
|
await StickerMarket.methods.setRegisterFee(registerFee).send();
|
2019-06-05 17:35:01 +00:00
|
|
|
let testPack = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
|
|
let testPackPrice = "0";
|
|
|
|
let packOwner = accounts[1];
|
|
|
|
let packBuyer = accounts[2];
|
2019-06-14 04:36:27 +00:00
|
|
|
let reg = await StickerMarket.methods.registerPack(testPackPrice, 0, ["0x00000000"], packOwner, testPack, registerFee).send();
|
2019-06-05 17:35:01 +00:00
|
|
|
let packId = reg.events.Register.returnValues.packId;
|
|
|
|
await TestStatusNetwork.methods.mint("1").send({from: packBuyer });
|
|
|
|
await MiniMeToken.methods.approve(StickerMarket.address, "1").send({from: packBuyer });
|
2019-06-12 05:05:46 +00:00
|
|
|
Utils.expectThrow(StickerMarket.methods.buyToken(packId, packBuyer, testPackPrice).send({from: packBuyer }));
|
2019-06-05 17:35:01 +00:00
|
|
|
await StickerMarket.methods.purgePack(packId, 0).send();
|
|
|
|
});
|
|
|
|
|
2019-06-14 04:36:27 +00:00
|
|
|
it("should migrate", async function() {
|
2019-06-05 17:35:01 +00:00
|
|
|
await StickerMarket.methods.setMarketState(3).send();
|
2019-06-14 04:36:27 +00:00
|
|
|
await StickerMarket.methods.migrate(StickerMarketMigrated.options.address).send();
|
2019-06-05 17:35:01 +00:00
|
|
|
|
|
|
|
let testPack = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
|
|
let testPackPrice = "0";
|
|
|
|
let packOwner = accounts[1];
|
|
|
|
let packBuyer = accounts[2];
|
2019-06-14 04:36:27 +00:00
|
|
|
let reg = await StickerMarketMigrated.methods.registerPack(testPackPrice, 0, ["0x00000000"], packOwner, testPack, registerFee).send();
|
2019-06-05 17:35:01 +00:00
|
|
|
let packId = reg.events.Register.returnValues.packId;
|
|
|
|
await TestStatusNetwork.methods.mint("1").send({from: packBuyer });
|
2019-06-14 04:36:27 +00:00
|
|
|
await StickerMarketMigrated.methods.buyToken(packId, packBuyer, testPackPrice).send({from: packBuyer });
|
2019-06-05 17:35:01 +00:00
|
|
|
await StickerMarketMigrated.methods.purgePack(packId, 0).send();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|