Socket
Socket
Sign inDemoInstall

4irelabs-blackchain-smart-contract

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

4irelabs-blackchain-smart-contract - npm Package Compare versions

Comparing version 0.0.46 to 0.0.47

5

dist/src/types.d.ts

@@ -8,3 +8,3 @@ import * as Anchor from "@project-serum/anchor";

status: Status;
potions: (PotionsEffect | null)[];
potions: PotionsEffect[];
};

@@ -1200,2 +1200,5 @@ export declare type PlayerAccount = TypeDef<BlackchainProgram["accounts"]["7"], Anchor.IdlTypes<BlackchainProgram>>;

};
NoPotion: {
noPotion: {};
};
};

@@ -1202,0 +1205,0 @@ export declare type Potion = typeof PotionEnum[keyof typeof PotionEnum];

1

dist/src/types.js

@@ -416,2 +416,3 @@ "use strict";

ArtisansPotion: { artisansPotion: {} },
NoPotion: { noPotion: {} },
};

@@ -418,0 +419,0 @@ exports.MaterialTypeEnum = {

@@ -41,4 +41,26 @@ "use strict";

test("Create player account", () => __awaiter(void 0, void 0, void 0, function* () {
console.log(yield bc.getPlayerAccount(new web3_js_1.PublicKey("BgfXjkCaTB9cfg7SfQGBpdnJBGnQPMoDTF6Skd9w9PEy")));
console.log(yield bc.getPlayerAccount(new web3_js_1.PublicKey("2vw8Hia8E9DEurAzMhySZbj9nZfJtaEnTiT8AJjS8GiM")));
// console.log(
// (
// await bc.getCharacter(
// new PublicKey("5ykdtqfVBBpz6VzKxBoJuDs9rDoC9L1p2suJfsio97W")
// )
// )?.leftHand.toString()
// );
// console.log(
// (
// await bc.getWeapon(
// new PublicKey("2X4zakkqCE5UARzVSrFqsoqeCNPeFnQ3TEod9QYbsEuP")
// )
// )?.weaponTyp
// );
// console.log(
// await bc.getBattleLog(
// "35xsen7UqwSc3rQbcfvG94Y6tcmEwipE3vK1T5LaHPh9M34i6ytRKSnK9FECGyD1mgyUYHHRpinWGHjKTvSDBXWB"
// )
// );
// console.log(
// await bc.getPlayerAccount(
// new PublicKey("2vw8Hia8E9DEurAzMhySZbj9nZfJtaEnTiT8AJjS8GiM")
// )
// );
yield bc.createPlayerAccount();

@@ -69,3 +91,5 @@ const player = yield bc.getPlayerAccount();

expect(consumables[1].consumables).toEqual((() => {
let arr = Object.entries(types_1.PotionEnum).map((e, i) => {
let arr = Object.entries(types_1.PotionEnum)
.filter((e, i) => e[0] !== "NoPotion")
.map((e, i) => {
return { typ: e[1], amount: new anchor_1.BN(Array(16).fill(0)) };

@@ -97,2 +121,12 @@ });

.reduce((acc, ch) => acc + String.fromCharCode(ch), "")).toBe("Dragon");
expect(character.potions.map((x) => [
x.effectEnd.toString(),
(0, types_1.enumEq)(x.effect, types_1.PotionEnum.NoPotion),
])).toEqual([
["0", true],
["0", true],
["0", true],
["0", true],
["0", true],
]);
}));

@@ -109,9 +143,8 @@ test("Set character in tavern", () => __awaiter(void 0, void 0, void 0, function* () {

expect((0, types_1.enumEq)(character.status, types_1.StatusEnum.Close)).toBe(true);
expect(character.potions).toEqual([null, null, null, null, null]);
}));
test("Blind raid", () => __awaiter(void 0, void 0, void 0, function* () {
// for (let i = 0; i < 10; i++) {
// for (let i = 0; i < 5; i++) {
const player = (yield bc.getPlayerAccount());
const characterBefore = (yield bc.getCharacter(player.characters[0]));
let tx = yield bc.blindRaid(types_1.DifficultyEnum.Hard, player.characters[0]);
let tx = yield bc.blindRaid(types_1.DifficultyEnum.Easy, player.characters[0]);
expect(typeof tx).not.toBe("number");

@@ -124,2 +157,3 @@ let sign = yield bc.sendTransaction(tx[0]);

battleLog = battleLog;
//console.log(battleLog);
let initDungeon = yield bc.getInitialDungeon(sign);

@@ -139,25 +173,3 @@ expect(typeof initDungeon).not.toBe("number");

expect(battleLog.receivedExp.toString()).toBe(characterAfter.experience.sub(characterBefore.experience).toString());
// // console.log(
// // await Promise.all(
// // battleLog.items
// // .filter((x) => enumEq(x.artifactType, ArtifactTypeEnum.Weapon))
// // .map(async (x) => (await bc.getWeapon(x.key))?.weaponTyp)
// // )
// // );
// // console.log(
// // await Promise.all(
// // battleLog.items
// // .filter((x) => enumEq(x.artifactType, ArtifactTypeEnum.Armor))
// // .map(async (x) => (await bc.getArmor(x.key))?.armorTyp)
// // )
// // );
// // console.log(
// // await Promise.all(
// // battleLog.items
// // .filter((x) => enumEq(x.artifactType, ArtifactTypeEnum.Shield))
// // .map(async (x) => (await bc.getShield(x.key))?.typ)
// // )
// // );
// console.log(initDungeon.branches.map((x) => x.enemy?.typ));
// }
//}
}));

@@ -176,4 +188,2 @@ test("Set weapon with bonus", () => __awaiter(void 0, void 0, void 0, function* () {

yield bc.sendTransaction(yield bc.instructionsToBuffer([tx1]));
console.log(w[1].bonuses);
console.log(yield bc.getCharacter(character[0]));
break;

@@ -183,72 +193,61 @@ }

}));
// 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");
// 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");
break;
}
}
}));
test("Use potions", () => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b;
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) && m.amount.gtn(0)) {
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];

@@ -259,7 +258,5 @@ let tx = yield bc.usePotion(characterBefore[0], m.typ);

let characterAfter = (yield bc.getCharactersList())[0];
expect((0, types_1.enumEq)((_a = characterAfter[1].potions[0]) === null || _a === void 0 ? void 0 : _a.effect, types_1.PotionEnum.PotionOfClearMind)).toBe(true);
expect((0, types_1.enumEq)((_b = characterAfter[1].potions[0]) === null || _b === void 0 ? void 0 : _b.effect, types_1.PotionEnum.PotionOfClearMind)).toBe(true);
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[1].consumables[types_1.consumablesTypeMap.get(JSON.stringify(types_1.PotionEnum.PotionOfClearMind))].amount.toString()).toBe(m.amount.subn(1).toString());
console.log("use");
expect(consumables.consumables[types_1.consumablesTypeMap.get(JSON.stringify(m.typ))].amount.toString()).toBe(m.amount.subn(1).toString());
break;

@@ -269,2 +266,17 @@ }

}));
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* () {

@@ -284,7 +296,12 @@ // for (let i = 0; i < 100; i++) {

for (let m of consumables.consumables) {
if (m.amount.gtn(0) && (0, types_1.enumEq)(m.typ, types_1.PotionEnum.LesserHealingPotion)) {
console.log(m.typ);
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;
break;
}

@@ -300,3 +317,3 @@ }

battleLog = battleLog;
console.log(battleLog.battleLog);
console.log(battleLog);
if (battleLog.complete != 100) {

@@ -313,85 +330,74 @@ let dungeon = yield bc.getDungeon(tx1[1]);

expect(battleLog.receivedExp.toString()).toBe(characterAfter.experience.sub(characterBefore.experience).toString());
if (potion[0] !== undefined) {
if (potion[0] !== undefined && battleLog.consumables.length == 0) {
let con = yield bc.getConsumables();
expect(con).not.toBeNull();
console.log(potion[0]);
console.log(types_1.consumablesTypeMap.get(JSON.stringify(potion[0])));
console.log(potion);
con = con;
expect(con[1].consumables[types_1.consumablesTypeMap.get(JSON.stringify(potion[0]))].amount.toString()).toBe(p.subn(1).toString());
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", 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("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.46",
"version": "0.0.47",
"description": "Integration with Solana API",

@@ -5,0 +5,0 @@ "author": "",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc