4irelabs-blackchain-smart-contract
Advanced tools
Comparing version 0.0.52 to 0.0.53
@@ -19,2 +19,3 @@ "use strict"; | ||
const bignumber_js_1 = __importDefault(require("bignumber.js")); | ||
//import { feeAccount } from "../tests/constants"; | ||
function getGoldMintPublicKey(programId) { | ||
@@ -31,2 +32,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
return feePdaAccount; | ||
//return [new PublicKey(feeAccount), 0]; | ||
}); | ||
@@ -33,0 +35,0 @@ } |
@@ -6,2 +6,2 @@ "use strict"; | ||
exports.KEY = "DfUYMPUztLXR7fZTVYMr46xrMyyyBHw4LP4Koogzyho3"; | ||
exports.cluster = constants_1.Cluster.localnet; | ||
exports.cluster = constants_1.Cluster.testnet; |
@@ -111,3 +111,3 @@ "use strict"; | ||
//await bc.addRoom(); | ||
let tx = yield bc.hireCharacterWithoutSending("Dragon", types_1.ClassEnum.Templar); | ||
let tx = yield bc.hireCharacterWithoutSending("Dragon", types_1.ClassEnum.Pyromancer); | ||
expect(typeof tx).not.toBe("number"); | ||
@@ -147,3 +147,3 @@ yield bc.sendTransaction(tx[0]); | ||
const characterBefore = (yield bc.getCharacter(player.characters[0])); | ||
let tx = yield bc.blindRaid(types_1.DifficultyEnum.Easy, player.characters[0]); | ||
let tx = yield bc.blindRaid(types_1.DifficultyEnum.Hard, player.characters[0]); | ||
expect(typeof tx).not.toBe("number"); | ||
@@ -173,347 +173,245 @@ let sign = yield bc.sendTransaction(tx[0]); | ||
})); | ||
// test("Use golds", async () => { | ||
// let consumablesBefore = (await bc.getConsumables()) as [ | ||
// PublicKey, | ||
// Consumables | ||
// ]; | ||
// let gold = await bc.getGoldCount(); | ||
// expect(gold).not.toBeNull(); | ||
// gold = gold as BN; | ||
// let tx = await bc.buyConsumableForGold(PotionEnum.RejuvenationHoneydew, 1); | ||
// expect(typeof tx).not.toBe("number"); | ||
// await bc.sendTransaction(tx as Buffer); | ||
// expect(gold.subn(100).toString()).toBe((await bc.getGoldCount()).toString()); | ||
// let consumablesAfter = (await bc.getConsumables()) as [ | ||
// PublicKey, | ||
// Consumables | ||
// ]; | ||
// expect( | ||
// consumablesBefore[1].consumables[ | ||
// consumablesTypeMap.get(JSON.stringify(PotionEnum.RejuvenationHoneydew)) | ||
// ].amount.toString() | ||
// ).toBe("0"); | ||
// expect( | ||
// consumablesBefore[1].consumables[ | ||
// consumablesTypeMap.get(JSON.stringify(PotionEnum.RejuvenationHoneydew)) | ||
// ].amount | ||
// .addn(1) | ||
// .toString() | ||
// ).toBe( | ||
// consumablesAfter[1].consumables[ | ||
// consumablesTypeMap.get(JSON.stringify(PotionEnum.RejuvenationHoneydew)) | ||
// ].amount.toString() | ||
// ); | ||
// let tx1 = await bc.deleteConsumable(PotionEnum.RejuvenationHoneydew, 1); | ||
// await bc.sendTransaction(tx1 as Buffer); | ||
// consumablesAfter = (await bc.getConsumables()) as [PublicKey, Consumables]; | ||
// expect( | ||
// consumablesBefore[1].consumables[ | ||
// consumablesTypeMap.get(JSON.stringify(PotionEnum.RejuvenationHoneydew)) | ||
// ].amount.toString() | ||
// ).toBe( | ||
// consumablesAfter[1].consumables[ | ||
// consumablesTypeMap.get(JSON.stringify(PotionEnum.RejuvenationHoneydew)) | ||
// ].amount.toString() | ||
// ); | ||
// }); | ||
// test("Set weapon with bonus", async () => { | ||
// let weapons = (await bc.getWeaponsList()) as [PublicKey, Weapon][]; | ||
// let character = ( | ||
// (await bc.getCharactersList()) as [PublicKey, Character][] | ||
// )[0]; | ||
// for (let w of weapons) { | ||
// if ( | ||
// enumEq(w[1].rank, RankEnum.Rare) || | ||
// enumEq(w[1].rank, RankEnum.Epic) || | ||
// enumEq(w[1].rank, RankEnum.Legendary) || | ||
// enumEq(w[1].rank, RankEnum.Mythic) | ||
// ) { | ||
// let tx = await bc.unsetWeaponWithoutSending( | ||
// character[0], | ||
// character[1].rightHand | ||
// ); | ||
// await bc.sendTransaction(await bc.instructionsToBuffer([tx])); | ||
// let tx1 = await bc.setWeaponWithoutSending(character[0], w[0]); | ||
// await bc.sendTransaction(await bc.instructionsToBuffer([tx1])); | ||
// break; | ||
// } | ||
// } | ||
// }); | ||
// test("Lock material", async () => { | ||
// let materials = ((await bc.getMaterials()) as [PublicKey, Materials])[1]; | ||
// for (let m of materials.materials) { | ||
// if (m.amount.gtn(1)) { | ||
// let tx = await bc.lockMaterial(0.001, 2, m.typ); | ||
// expect(typeof tx).not.toBe("number"); | ||
// await bc.sendTransaction(tx[0] as Buffer); | ||
// let lot = await bc.getMaterialLot(tx[1]); | ||
// expect(lot).not.toBeNull(); | ||
// lot = lot as MaterialLot; | ||
// expect(lot.amount.toNumber()).toBe(2); | ||
// expect(enumEq(lot.typ, m.typ)).toBe(true); | ||
// expect(lot.price.toNumber()).toBe(0.001 * 10 ** 9); | ||
// expect(lot.isInitialized).toBe(true); | ||
// let tx1 = await bc.changeMaterialLot(tx[1], 0.01, 1); | ||
// expect(typeof tx).not.toBe("number"); | ||
// await bc.sendTransaction(tx1 as Buffer); | ||
// lot = await bc.getMaterialLot(tx[1]); | ||
// expect(lot).not.toBeNull(); | ||
// lot = lot as MaterialLot; | ||
// expect(lot.amount.toNumber()).toBe(1); | ||
// expect(enumEq(lot.typ, m.typ)).toBe(true); | ||
// expect(lot.price.toNumber()).toBe(0.01 * 10 ** 9); | ||
// expect(lot.isInitialized).toBe(true); | ||
// let keypair = new Keypair(); | ||
// let wallet = new NodeWallet(keypair); | ||
// let connection = new web3.Connection(cluster, "finalized"); | ||
// let sign = await connection.requestAirdrop( | ||
// keypair.publicKey, | ||
// 1 * web3.LAMPORTS_PER_SOL | ||
// ); | ||
// await connection.confirmTransaction(sign); | ||
// let bcBuyer = new BC(cluster, KEY, true, wallet); | ||
// await bcBuyer.createPlayerAccount(); | ||
// let startSol = await connection.getBalance( | ||
// keypair.publicKey, | ||
// "finalized" | ||
// ); | ||
// let buyTx = await bcBuyer.buyMaterial(tx[1], 1); | ||
// await bcBuyer.sendTransaction(buyTx as Buffer); | ||
// let buyMaterial = await bcBuyer.getMaterials(); | ||
// expect(buyMaterial).not.toBeNull(); | ||
// buyMaterial = buyMaterial as [PublicKey, Materials]; | ||
// expect( | ||
// buyMaterial[1].materials[ | ||
// materialTypeMap.get(JSON.stringify(lot.typ)) | ||
// ].amount.toString() | ||
// ).toBe("1"); | ||
// expect(startSol - 0.01 * 10 ** 9 - 5000).toBe( | ||
// await connection.getBalance(keypair.publicKey, "finalized") | ||
// ); | ||
// tx1 = await bcBuyer.deleteMaterial(m.typ, 1); | ||
// await bcBuyer.sendTransaction(tx1 as Buffer); | ||
// buyMaterial = await bcBuyer.getMaterials(); | ||
// expect(buyMaterial).not.toBeNull(); | ||
// buyMaterial = buyMaterial as [PublicKey, Materials]; | ||
// expect( | ||
// buyMaterial[1].materials[ | ||
// materialTypeMap.get(JSON.stringify(lot.typ)) | ||
// ].amount.toString() | ||
// ).toBe("0"); | ||
// let sellMaterial = await bc.getMaterials(); | ||
// expect(sellMaterial).not.toBeNull(); | ||
// sellMaterial = sellMaterial as [PublicKey, Materials]; | ||
// expect( | ||
// sellMaterial[1].materials[ | ||
// materialTypeMap.get(JSON.stringify(m.typ)) | ||
// ].amount.toString() | ||
// ).toBe(m.amount.subn(1).toString()); | ||
// break; | ||
// } | ||
// } | ||
// }); | ||
// test("Use potions", async () => { | ||
// let consumables = ( | ||
// (await bc.getConsumables()) as [PublicKey, Consumables] | ||
// )[1]; | ||
// for (let m of consumables.consumables) { | ||
// if ( | ||
// (enumEq(m.typ, PotionEnum.PotionOfClearMind) || | ||
// enumEq(m.typ, PotionEnum.PotionOfHeavyArms) || | ||
// enumEq(m.typ, PotionEnum.PotionOfSneakyCat) || | ||
// enumEq(m.typ, PotionEnum.PotionOfTheHappyFool) || | ||
// enumEq(m.typ, PotionEnum.PotionOfElephant)) && | ||
// m.amount.gtn(0) | ||
// ) { | ||
// let characterBefore = ( | ||
// (await bc.getCharactersList()) as [PublicKey, Character][] | ||
// )[0]; | ||
// let tx = await bc.usePotion(characterBefore[0], m.typ); | ||
// expect(typeof tx).not.toBe("number"); | ||
// await bc.sendTransaction(tx as Buffer); | ||
// let characterAfter = ( | ||
// (await bc.getCharactersList()) as [PublicKey, Character][] | ||
// )[0]; | ||
// expect(enumEq(characterAfter[1].potions[0]?.effect, m.typ)).toBe(true); | ||
// let consumables = ( | ||
// (await bc.getConsumables()) as [PublicKey, Consumables] | ||
// )[1]; | ||
// expect( | ||
// consumables.consumables[ | ||
// consumablesTypeMap.get(JSON.stringify(m.typ)) | ||
// ].amount.toString() | ||
// ).toBe(m.amount.subn(1).toString()); | ||
// break; | ||
// } | ||
// } | ||
// }); | ||
// test("Increase stats", async () => { | ||
// const player = (await bc.getPlayerAccount()) as PlayerAccount; | ||
// const characterBefore = (await bc.getCharacter( | ||
// player.characters[0] | ||
// )) as Character; | ||
// let points = characterBefore.skillPoints; | ||
// let tx = await bc.upgradeStatsCharacter(player.characters[0], { | ||
// str: points, | ||
// }); | ||
// await bc.sendTransaction(tx as Buffer); | ||
// const characterAfter = (await bc.getCharacter( | ||
// player.characters[0] | ||
// )) as Character; | ||
// if (characterBefore.injuryLevel !== 0) { | ||
// expect(characterBefore.startsStat[0] + points).toBe( | ||
// characterAfter.startsStat[0] | ||
// ); | ||
// } else expect(characterBefore.str + points).toBe(characterAfter.str); | ||
// }); | ||
// test("Scouting & raid", async () => { | ||
// // for (let i = 0; i < 100; i++) { | ||
// const player = (await bc.getPlayerAccount()) as PlayerAccount; | ||
// const characterBefore = (await bc.getCharacter( | ||
// player.characters[0] | ||
// )) as Character; | ||
// let tx1 = await bc.scoutDungeonWithoutSending( | ||
// DifficultyEnum.Hard, | ||
// player.characters[0] | ||
// ); | ||
// expect(typeof tx1).not.toBe("number"); | ||
// await bc.sendTransaction(tx1[0] as Buffer); | ||
// let initDungeon = await bc.getDungeon(tx1[1]); | ||
// expect(initDungeon).not.toBeNull(); | ||
// initDungeon = initDungeon as Dungeon; | ||
// let consumables = ( | ||
// (await bc.getConsumables()) as [PublicKey, Consumables] | ||
// )[1]; | ||
// let potion: Potion[] = []; | ||
// let p = new BN(); | ||
// for (let m of consumables.consumables) { | ||
// if ( | ||
// m.amount.gtn(0) && | ||
// (enumEq(m.typ, PotionEnum.LesserHealingPotion) || | ||
// enumEq(m.typ, PotionEnum.CommonHealingPotion) || | ||
// enumEq(m.typ, PotionEnum.FinestHealingPotion) || | ||
// enumEq(m.typ, PotionEnum.GreatHealingPotion) || | ||
// enumEq(m.typ, PotionEnum.MinorHealingPotion) || | ||
// enumEq(m.typ, PotionEnum.SeekersStone) || | ||
// enumEq(m.typ, PotionEnum.PhilosophianStoneReplica)) | ||
// ) { | ||
// potion.push(m.typ); | ||
// p = m.amount; | ||
// } | ||
// } | ||
// let tx = await bc.raid(tx1[1], player.characters[0], potion); | ||
// expect(typeof tx).not.toBe("number"); | ||
// let sign = await bc.sendTransaction(tx as Buffer); | ||
// expect(typeof sign).toBe("string"); | ||
// sign = sign as string; | ||
// let battleLog = await bc.getBattleLog(sign); | ||
// expect(typeof battleLog).not.toBe("number"); | ||
// battleLog = battleLog as BattleLog; | ||
// console.log(battleLog); | ||
// if (battleLog.complete != 100) { | ||
// let dungeon = await bc.getDungeon(tx1[1]); | ||
// expect(dungeon).not.toBeNull(); | ||
// dungeon = dungeon as Dungeon; | ||
// expect(battleLog.receivedExp.toString()).toBe( | ||
// initDungeon.exp.sub(dungeon.exp).toString() | ||
// ); | ||
// } else { | ||
// expect(battleLog.receivedExp.toString()).toBe( | ||
// initDungeon.exp.subn(0).toString() | ||
// ); | ||
// } | ||
// const characterAfter = (await bc.getCharacter( | ||
// player.characters[0] | ||
// )) as Character; | ||
// expect(battleLog.receivedExp.toString()).toBe( | ||
// characterAfter.experience.sub(characterBefore.experience).toString() | ||
// ); | ||
// if (potion[0] !== undefined && battleLog.consumables.length == 0) { | ||
// let con = await bc.getConsumables(); | ||
// expect(con).not.toBeNull(); | ||
// console.log(potion); | ||
// con = con as [PublicKey, Consumables]; | ||
// for (let pot of potion) { | ||
// expect( | ||
// con[1].consumables[ | ||
// consumablesTypeMap.get(JSON.stringify(pot)) | ||
// ].amount.toString() | ||
// ).toBe(p.subn(1).toString()); | ||
// } | ||
// } | ||
// //} | ||
// }); | ||
// test("Lock consumable", async () => { | ||
// let consumables = ( | ||
// (await bc.getConsumables()) as [PublicKey, Consumables] | ||
// )[1]; | ||
// for (let m of consumables.consumables) { | ||
// if (m.amount.gtn(0)) { | ||
// let tx = await bc.lockConsumable(100, 1, m.typ); | ||
// expect(typeof tx).not.toBe("number"); | ||
// await bc.sendTransaction(tx[0] as Buffer); | ||
// let lot = await bc.getConsumableLot(tx[1]); | ||
// expect(lot).not.toBeNull(); | ||
// lot = lot as ConsumableLot; | ||
// expect(lot.amount.toNumber()).toBe(1); | ||
// expect(enumEq(lot.typ, m.typ)).toBe(true); | ||
// expect(lot.price.toNumber()).toBe(100 * 10 ** 9); | ||
// expect(lot.isInitialized).toBe(true); | ||
// let tx1 = await bc.unlockConsumable(tx[1]); | ||
// expect(typeof tx).not.toBe("number"); | ||
// await bc.sendTransaction(tx1 as Buffer); | ||
// lot = await bc.getConsumableLot(tx[1]); | ||
// expect(lot).toBeNull(); | ||
// break; | ||
// } | ||
// } | ||
// }); | ||
// test("Lock weapon", async () => { | ||
// let weapons = (await bc.getWeaponsList()) as [PublicKey, Weapon][]; | ||
// for (let w of weapons) { | ||
// if (enumEq(w[1].status, StatusEnum.Free)) { | ||
// let tx = await bc.lockWeapon(w[0], 0.4); | ||
// await bc.sendTransaction(tx as Buffer); | ||
// let weapon = await bc.getWeapon(w[0]); | ||
// expect(weapon).not.toBeNull(); | ||
// weapon = weapon as Weapon; | ||
// expect(weapon.price.toNumber()).toBe(0.4 * 10 ** 9); | ||
// tx = await bc.changeWeaponLot(w[0], 0.5); | ||
// await bc.sendTransaction(tx as Buffer); | ||
// weapon = await bc.getWeapon(w[0]); | ||
// expect(weapon).not.toBeNull(); | ||
// weapon = weapon as Weapon; | ||
// expect(weapon.price.toNumber()).toBe(0.5 * 10 ** 9); | ||
// let keypair = new Keypair(); | ||
// let wallet = new NodeWallet(keypair); | ||
// let connection = new web3.Connection(cluster, "finalized"); | ||
// let sign = await connection.requestAirdrop( | ||
// keypair.publicKey, | ||
// 1 * web3.LAMPORTS_PER_SOL | ||
// ); | ||
// await connection.confirmTransaction(sign); | ||
// let bcBuyer = new BC(cluster, KEY, true, wallet); | ||
// await bcBuyer.createPlayerAccount(); | ||
// let startSol = await connection.getBalance( | ||
// keypair.publicKey, | ||
// "finalized" | ||
// ); | ||
// let buyTx = await bcBuyer.buyWeapon(w[0]); | ||
// await bcBuyer.sendTransaction(buyTx as Buffer); | ||
// let buyWeapons = await bcBuyer.getWeaponsList(); | ||
// expect(buyWeapons).not.toBeNull(); | ||
// buyWeapons = buyWeapons as [PublicKey, Weapon][]; | ||
// expect(buyWeapons[0][0].toString()).toBe(w[0].toString()); | ||
// expect(startSol - 0.5 * 10 ** 9 - 5000).toBe( | ||
// await connection.getBalance(keypair.publicKey, "finalized") | ||
// ); | ||
// let soldWeapon = (await bcBuyer.getWeapon(w[0])) as Weapon; | ||
// expect(soldWeapon.price.toString()).toBe("0"); | ||
// expect(enumEq(soldWeapon.status, StatusEnum.Free)).toBe(true); | ||
// expect(soldWeapon.playerAccount.toString()).toBe( | ||
// (await bc.getPlayerAccountPublicKey(keypair.publicKey)).toString() | ||
// ); | ||
// break; | ||
// } | ||
// } | ||
// }); | ||
test("Use golds", () => __awaiter(void 0, void 0, void 0, function* () { | ||
let consumablesBefore = (yield bc.getConsumables()); | ||
let gold = yield bc.getGoldCount(); | ||
expect(gold).not.toBeNull(); | ||
gold = gold; | ||
let tx = yield bc.buyConsumableForGold(types_1.PotionEnum.RejuvenationHoneydew, 1); | ||
expect(typeof tx).not.toBe("number"); | ||
yield bc.sendTransaction(tx); | ||
expect(gold.subn(100).toString()).toBe((yield bc.getGoldCount()).toString()); | ||
let consumablesAfter = (yield bc.getConsumables()); | ||
expect(consumablesBefore[1].consumables[types_1.consumablesTypeMap.get(JSON.stringify(types_1.PotionEnum.RejuvenationHoneydew))].amount.toString()).toBe("0"); | ||
expect(consumablesBefore[1].consumables[types_1.consumablesTypeMap.get(JSON.stringify(types_1.PotionEnum.RejuvenationHoneydew))].amount | ||
.addn(1) | ||
.toString()).toBe(consumablesAfter[1].consumables[types_1.consumablesTypeMap.get(JSON.stringify(types_1.PotionEnum.RejuvenationHoneydew))].amount.toString()); | ||
let tx1 = yield bc.deleteConsumable(types_1.PotionEnum.RejuvenationHoneydew, 1); | ||
yield bc.sendTransaction(tx1); | ||
consumablesAfter = (yield bc.getConsumables()); | ||
expect(consumablesBefore[1].consumables[types_1.consumablesTypeMap.get(JSON.stringify(types_1.PotionEnum.RejuvenationHoneydew))].amount.toString()).toBe(consumablesAfter[1].consumables[types_1.consumablesTypeMap.get(JSON.stringify(types_1.PotionEnum.RejuvenationHoneydew))].amount.toString()); | ||
})); | ||
test("Set weapon with bonus", () => __awaiter(void 0, void 0, void 0, function* () { | ||
let weapons = (yield bc.getWeaponsList()); | ||
let character = (yield bc.getCharactersList())[0]; | ||
for (let w of weapons) { | ||
if ((0, types_1.enumEq)(w[1].rank, types_1.RankEnum.Rare) || | ||
(0, types_1.enumEq)(w[1].rank, types_1.RankEnum.Epic) || | ||
(0, types_1.enumEq)(w[1].rank, types_1.RankEnum.Legendary) || | ||
(0, types_1.enumEq)(w[1].rank, types_1.RankEnum.Mythic)) { | ||
let tx = yield bc.unsetWeaponWithoutSending(character[0], character[1].rightHand); | ||
yield bc.sendTransaction(yield bc.instructionsToBuffer([tx])); | ||
let tx1 = yield bc.setWeaponWithoutSending(character[0], w[0]); | ||
yield bc.sendTransaction(yield bc.instructionsToBuffer([tx1])); | ||
break; | ||
} | ||
} | ||
})); | ||
test("Lock material", () => __awaiter(void 0, void 0, void 0, function* () { | ||
let materials = (yield bc.getMaterials())[1]; | ||
for (let m of materials.materials) { | ||
if (m.amount.gtn(1)) { | ||
let tx = yield bc.lockMaterial(0.001, 2, m.typ); | ||
expect(typeof tx).not.toBe("number"); | ||
yield bc.sendTransaction(tx[0]); | ||
let lot = yield bc.getMaterialLot(tx[1]); | ||
expect(lot).not.toBeNull(); | ||
lot = lot; | ||
expect(lot.amount.toNumber()).toBe(2); | ||
expect((0, types_1.enumEq)(lot.typ, m.typ)).toBe(true); | ||
expect(lot.price.toNumber()).toBe(0.001 * Math.pow(10, 9)); | ||
expect(lot.isInitialized).toBe(true); | ||
let tx1 = yield bc.changeMaterialLot(tx[1], 0.01, 1); | ||
expect(typeof tx).not.toBe("number"); | ||
yield bc.sendTransaction(tx1); | ||
lot = yield bc.getMaterialLot(tx[1]); | ||
expect(lot).not.toBeNull(); | ||
lot = lot; | ||
expect(lot.amount.toNumber()).toBe(1); | ||
expect((0, types_1.enumEq)(lot.typ, m.typ)).toBe(true); | ||
expect(lot.price.toNumber()).toBe(0.01 * Math.pow(10, 9)); | ||
expect(lot.isInitialized).toBe(true); | ||
let keypair = new web3_js_1.Keypair(); | ||
let wallet = new nodewallet_1.default(keypair); | ||
let connection = new anchor_1.web3.Connection(constants_2.cluster, "finalized"); | ||
let sign = yield connection.requestAirdrop(keypair.publicKey, 1 * anchor_1.web3.LAMPORTS_PER_SOL); | ||
yield connection.confirmTransaction(sign); | ||
let bcBuyer = new src_1.BC(constants_2.cluster, constants_2.KEY, true, wallet); | ||
yield bcBuyer.createPlayerAccount(); | ||
let startSol = yield connection.getBalance(keypair.publicKey, "finalized"); | ||
let buyTx = yield bcBuyer.buyMaterial(tx[1], 1); | ||
yield bcBuyer.sendTransaction(buyTx); | ||
let buyMaterial = yield bcBuyer.getMaterials(); | ||
expect(buyMaterial).not.toBeNull(); | ||
buyMaterial = buyMaterial; | ||
expect(buyMaterial[1].materials[types_1.materialTypeMap.get(JSON.stringify(lot.typ))].amount.toString()).toBe("1"); | ||
expect(startSol - 0.01 * Math.pow(10, 9) - 5000).toBe(yield connection.getBalance(keypair.publicKey, "finalized")); | ||
tx1 = yield bcBuyer.deleteMaterial(m.typ, 1); | ||
yield bcBuyer.sendTransaction(tx1); | ||
buyMaterial = yield bcBuyer.getMaterials(); | ||
expect(buyMaterial).not.toBeNull(); | ||
buyMaterial = buyMaterial; | ||
expect(buyMaterial[1].materials[types_1.materialTypeMap.get(JSON.stringify(lot.typ))].amount.toString()).toBe("0"); | ||
let sellMaterial = yield bc.getMaterials(); | ||
expect(sellMaterial).not.toBeNull(); | ||
sellMaterial = sellMaterial; | ||
expect(sellMaterial[1].materials[types_1.materialTypeMap.get(JSON.stringify(m.typ))].amount.toString()).toBe(m.amount.subn(1).toString()); | ||
break; | ||
} | ||
} | ||
})); | ||
test("Use potions", () => __awaiter(void 0, void 0, void 0, function* () { | ||
var _a; | ||
let consumables = (yield bc.getConsumables())[1]; | ||
for (let m of consumables.consumables) { | ||
if (((0, types_1.enumEq)(m.typ, types_1.PotionEnum.PotionOfClearMind) || | ||
(0, types_1.enumEq)(m.typ, types_1.PotionEnum.PotionOfHeavyArms) || | ||
(0, types_1.enumEq)(m.typ, types_1.PotionEnum.PotionOfSneakyCat) || | ||
(0, types_1.enumEq)(m.typ, types_1.PotionEnum.PotionOfTheHappyFool) || | ||
(0, types_1.enumEq)(m.typ, types_1.PotionEnum.PotionOfElephant)) && | ||
m.amount.gtn(0)) { | ||
let characterBefore = (yield bc.getCharactersList())[0]; | ||
let tx = yield bc.usePotion(characterBefore[0], m.typ); | ||
expect(typeof tx).not.toBe("number"); | ||
yield bc.sendTransaction(tx); | ||
let characterAfter = (yield bc.getCharactersList())[0]; | ||
expect((0, types_1.enumEq)((_a = characterAfter[1].potions[0]) === null || _a === void 0 ? void 0 : _a.effect, m.typ)).toBe(true); | ||
let consumables = (yield bc.getConsumables())[1]; | ||
expect(consumables.consumables[types_1.consumablesTypeMap.get(JSON.stringify(m.typ))].amount.toString()).toBe(m.amount.subn(1).toString()); | ||
break; | ||
} | ||
} | ||
})); | ||
test("Increase stats", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const player = (yield bc.getPlayerAccount()); | ||
const characterBefore = (yield bc.getCharacter(player.characters[0])); | ||
let points = characterBefore.skillPoints; | ||
let tx = yield bc.upgradeStatsCharacter(player.characters[0], { | ||
str: points, | ||
}); | ||
yield bc.sendTransaction(tx); | ||
const characterAfter = (yield bc.getCharacter(player.characters[0])); | ||
if (characterBefore.injuryLevel !== 0) { | ||
expect(characterBefore.startsStat[0] + points).toBe(characterAfter.startsStat[0]); | ||
} | ||
else | ||
expect(characterBefore.str + points).toBe(characterAfter.str); | ||
})); | ||
test("Scouting & raid", () => __awaiter(void 0, void 0, void 0, function* () { | ||
// for (let i = 0; i < 100; i++) { | ||
const player = (yield bc.getPlayerAccount()); | ||
const characterBefore = (yield bc.getCharacter(player.characters[0])); | ||
let tx1 = yield bc.scoutDungeonWithoutSending(types_1.DifficultyEnum.Hard, player.characters[0]); | ||
expect(typeof tx1).not.toBe("number"); | ||
yield bc.sendTransaction(tx1[0]); | ||
let initDungeon = yield bc.getDungeon(tx1[1]); | ||
expect(initDungeon).not.toBeNull(); | ||
initDungeon = initDungeon; | ||
let consumables = (yield bc.getConsumables())[1]; | ||
let potion = []; | ||
let p = new anchor_1.BN(); | ||
for (let m of consumables.consumables) { | ||
if (m.amount.gtn(0) && | ||
((0, types_1.enumEq)(m.typ, types_1.PotionEnum.LesserHealingPotion) || | ||
(0, types_1.enumEq)(m.typ, types_1.PotionEnum.CommonHealingPotion) || | ||
(0, types_1.enumEq)(m.typ, types_1.PotionEnum.FinestHealingPotion) || | ||
(0, types_1.enumEq)(m.typ, types_1.PotionEnum.GreatHealingPotion) || | ||
(0, types_1.enumEq)(m.typ, types_1.PotionEnum.MinorHealingPotion) || | ||
(0, types_1.enumEq)(m.typ, types_1.PotionEnum.SeekersStone) || | ||
(0, types_1.enumEq)(m.typ, types_1.PotionEnum.PhilosophianStoneReplica))) { | ||
potion.push(m.typ); | ||
p = m.amount; | ||
} | ||
} | ||
let tx = yield bc.raid(tx1[1], player.characters[0], potion); | ||
expect(typeof tx).not.toBe("number"); | ||
let sign = yield bc.sendTransaction(tx); | ||
expect(typeof sign).toBe("string"); | ||
sign = sign; | ||
let battleLog = yield bc.getBattleLog(sign); | ||
expect(typeof battleLog).not.toBe("number"); | ||
battleLog = battleLog; | ||
console.log(battleLog); | ||
if (battleLog.complete != 100) { | ||
let dungeon = yield bc.getDungeon(tx1[1]); | ||
expect(dungeon).not.toBeNull(); | ||
dungeon = dungeon; | ||
expect(battleLog.receivedExp.toString()).toBe(initDungeon.exp.sub(dungeon.exp).toString()); | ||
} | ||
else { | ||
expect(battleLog.receivedExp.toString()).toBe(initDungeon.exp.subn(0).toString()); | ||
} | ||
const characterAfter = (yield bc.getCharacter(player.characters[0])); | ||
expect(battleLog.receivedExp.toString()).toBe(characterAfter.experience.sub(characterBefore.experience).toString()); | ||
if (potion[0] !== undefined && battleLog.consumables.length == 0) { | ||
let con = yield bc.getConsumables(); | ||
expect(con).not.toBeNull(); | ||
console.log(potion); | ||
con = con; | ||
for (let pot of potion) { | ||
expect(con[1].consumables[types_1.consumablesTypeMap.get(JSON.stringify(pot))].amount.toString()).toBe(p.subn(1).toString()); | ||
} | ||
} | ||
//} | ||
})); | ||
test("Lock consumable", () => __awaiter(void 0, void 0, void 0, function* () { | ||
let consumables = (yield bc.getConsumables())[1]; | ||
for (let m of consumables.consumables) { | ||
if (m.amount.gtn(0)) { | ||
let tx = yield bc.lockConsumable(100, 1, m.typ); | ||
expect(typeof tx).not.toBe("number"); | ||
yield bc.sendTransaction(tx[0]); | ||
let lot = yield bc.getConsumableLot(tx[1]); | ||
expect(lot).not.toBeNull(); | ||
lot = lot; | ||
expect(lot.amount.toNumber()).toBe(1); | ||
expect((0, types_1.enumEq)(lot.typ, m.typ)).toBe(true); | ||
expect(lot.price.toNumber()).toBe(100 * Math.pow(10, 9)); | ||
expect(lot.isInitialized).toBe(true); | ||
let tx1 = yield bc.unlockConsumable(tx[1]); | ||
expect(typeof tx).not.toBe("number"); | ||
yield bc.sendTransaction(tx1); | ||
lot = yield bc.getConsumableLot(tx[1]); | ||
expect(lot).toBeNull(); | ||
break; | ||
} | ||
} | ||
})); | ||
test("Lock weapon", () => __awaiter(void 0, void 0, void 0, function* () { | ||
let weapons = (yield bc.getWeaponsList()); | ||
for (let w of weapons) { | ||
if ((0, types_1.enumEq)(w[1].status, types_1.StatusEnum.Free)) { | ||
let tx = yield bc.lockWeapon(w[0], 0.4); | ||
yield bc.sendTransaction(tx); | ||
let weapon = yield bc.getWeapon(w[0]); | ||
expect(weapon).not.toBeNull(); | ||
weapon = weapon; | ||
expect(weapon.price.toNumber()).toBe(0.4 * Math.pow(10, 9)); | ||
tx = yield bc.changeWeaponLot(w[0], 0.5); | ||
yield bc.sendTransaction(tx); | ||
weapon = yield bc.getWeapon(w[0]); | ||
expect(weapon).not.toBeNull(); | ||
weapon = weapon; | ||
expect(weapon.price.toNumber()).toBe(0.5 * Math.pow(10, 9)); | ||
let keypair = new web3_js_1.Keypair(); | ||
let wallet = new nodewallet_1.default(keypair); | ||
let connection = new anchor_1.web3.Connection(constants_2.cluster, "finalized"); | ||
let sign = yield connection.requestAirdrop(keypair.publicKey, 1 * anchor_1.web3.LAMPORTS_PER_SOL); | ||
yield connection.confirmTransaction(sign); | ||
let bcBuyer = new src_1.BC(constants_2.cluster, constants_2.KEY, true, wallet); | ||
yield bcBuyer.createPlayerAccount(); | ||
let startSol = yield connection.getBalance(keypair.publicKey, "finalized"); | ||
let buyTx = yield bcBuyer.buyWeapon(w[0]); | ||
yield bcBuyer.sendTransaction(buyTx); | ||
let buyWeapons = yield bcBuyer.getWeaponsList(); | ||
expect(buyWeapons).not.toBeNull(); | ||
buyWeapons = buyWeapons; | ||
expect(buyWeapons[0][0].toString()).toBe(w[0].toString()); | ||
expect(startSol - 0.5 * Math.pow(10, 9) - 5000).toBe(yield connection.getBalance(keypair.publicKey, "finalized")); | ||
let soldWeapon = (yield bcBuyer.getWeapon(w[0])); | ||
expect(soldWeapon.price.toString()).toBe("0"); | ||
expect((0, types_1.enumEq)(soldWeapon.status, types_1.StatusEnum.Free)).toBe(true); | ||
expect(soldWeapon.playerAccount.toString()).toBe((yield bc.getPlayerAccountPublicKey(keypair.publicKey)).toString()); | ||
break; | ||
} | ||
} | ||
})); |
{ | ||
"name": "4irelabs-blackchain-smart-contract", | ||
"version": "0.0.52", | ||
"version": "0.0.53", | ||
"description": "Integration with Solana API", | ||
@@ -5,0 +5,0 @@ "author": "", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
567530
17199