@vechain/vebetterdao-contracts
Version:
Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.
223 lines (222 loc) • 12.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const helpers_1 = require("../helpers");
const local_1 = require("@repo/config/contracts/envs/local");
const common_1 = require("../helpers/common");
const chai_1 = require("chai");
let owner;
let b3tr;
let treasury;
let nodeHolder;
let secondaryWallet;
let config;
let xAllocationVoting;
let governor;
let otherAccount;
let stargateNftMock;
let minterAccount;
let otherAccounts;
let nodeManagement;
let vechainNodes;
let stargateMock;
let galaxyMember;
describe("Galaxy Member - V6 Compatibility - @shard3c", function () {
beforeEach(async function () {
config = (0, local_1.createLocalConfig)();
const contracts = await (0, helpers_1.getOrDeployContractInstances)({
forceDeploy: true,
config,
deployMocks: true,
});
owner = contracts.owner;
b3tr = contracts.b3tr;
treasury = contracts.treasury;
nodeHolder = contracts.otherAccounts[0];
secondaryWallet = contracts.otherAccounts[10];
xAllocationVoting = contracts.xAllocationVoting;
governor = contracts.governor;
otherAccount = contracts.otherAccount;
stargateNftMock = contracts.stargateNftMock;
minterAccount = contracts.minterAccount;
otherAccounts = contracts.otherAccounts;
nodeManagement = contracts.nodeManagement;
vechainNodes = contracts.vechainNodesMock;
stargateMock = contracts.stargateMock;
galaxyMember = contracts.galaxyMember;
});
it("After Transferring an attached Node to a new owner, the attachment should be reset and GM downgraded", async function () {
// Bootstrap emissions
await (0, common_1.bootstrapEmissions)();
// Should be able to free mint after participating in allocation voting
await (0, common_1.participateInAllocationVoting)(owner, false, otherAccounts[10]);
//Set max level of GM to 10
await galaxyMember.connect(owner).setMaxLevel(10);
//Get stargate node
const nodeId = await (0, helpers_1.createNodeHolder)(7, owner);
// Mint GM to owner
await galaxyMember.connect(owner).freeMint();
const gmId = await galaxyMember.tokenOfOwnerByIndex(await owner.getAddress(), 0);
// Attach node to GM
await galaxyMember.connect(owner).attachNode(nodeId, gmId);
(0, chai_1.expect)(await galaxyMember.getNodeIdAttached(gmId)).to.equal(nodeId); //Should be attached
(0, chai_1.expect)(await galaxyMember.levelOf(gmId)).to.equal(7); //Should be in Saturn level
// Transfer node to otherAccount
await stargateNftMock.connect(owner).transferFrom(owner.address, otherAccount.address, nodeId);
// Expect attachment to be reset and GM downgraded
(0, chai_1.expect)(await galaxyMember.getNodeIdAttached(gmId)).to.equal(0);
(0, chai_1.expect)(await galaxyMember.levelOf(gmId)).to.equal(1);
});
it("Should NOT be able to transfer an attached GM", async function () {
// Bootstrap emissions
await (0, common_1.bootstrapEmissions)();
// Should be able to free mint after participating in allocation voting
await (0, common_1.participateInAllocationVoting)(owner, false, otherAccounts[10]);
//Set max level of GM to 10
await galaxyMember.connect(owner).setMaxLevel(10);
//Get stargate node
const nodeId = await (0, helpers_1.createNodeHolder)(7, owner);
// Mint GM to owner
await galaxyMember.connect(owner).freeMint();
const gmId = await galaxyMember.tokenOfOwnerByIndex(await owner.getAddress(), 0);
//Attach node to GM
await galaxyMember.connect(owner).attachNode(nodeId, gmId);
//Try to transfer GM to otherAccount
await (0, chai_1.expect)(galaxyMember.connect(owner).transferFrom(owner.address, otherAccount.address, gmId)).to.be.revertedWith("GalaxyMember: token attached to a node, detach before transfer");
});
it("Upon node manager change, attachment should reset and GM downgrade", async function () {
// Bootstrap emissions
await (0, common_1.bootstrapEmissions)();
// Should be able to free mint after participating in allocation voting
await (0, common_1.participateInAllocationVoting)(owner, false, otherAccounts[10]);
//Set max level of GM to 10
await galaxyMember.connect(owner).setMaxLevel(10);
//Get stargate node
const nodeId = await (0, helpers_1.createNodeHolder)(7, owner);
// Mint GM to owner
await galaxyMember.connect(owner).freeMint();
const gmId = await galaxyMember.tokenOfOwnerByIndex(await owner.getAddress(), 0);
//Attach node to GM
await galaxyMember.connect(owner).attachNode(nodeId, gmId);
//Change node manager to otherAccount
await stargateNftMock.connect(owner).addTokenManager(otherAccount.address, nodeId);
//Expect attachment to be reset and GM downgraded
(0, chai_1.expect)(await galaxyMember.getNodeIdAttached(gmId)).to.equal(0);
(0, chai_1.expect)(await galaxyMember.levelOf(gmId)).to.equal(1);
});
it("If unstake/burn stargate node, attachment should be reset and GM downgraded", async function () {
// Bootstrap emissions
await (0, common_1.bootstrapEmissions)();
// Should be able to free mint after participating in allocation voting
await (0, common_1.participateInAllocationVoting)(owner, false, otherAccounts[10]);
//Set max level of GM to 10
await galaxyMember.connect(owner).setMaxLevel(10);
//Get stargate node
const nodeId = await (0, helpers_1.createNodeHolder)(7, owner);
// Mint GM to owner
await galaxyMember.connect(owner).freeMint();
const gmId = await galaxyMember.tokenOfOwnerByIndex(await owner.getAddress(), 0);
//Attach node to GM
await galaxyMember.connect(owner).attachNode(nodeId, gmId);
//Unstake/burn node
await stargateMock.connect(owner).unstake(nodeId);
//Expect attachment to be reset and GM downgraded
(0, chai_1.expect)(await galaxyMember.getNodeIdAttached(gmId)).to.equal(0);
(0, chai_1.expect)(await galaxyMember.levelOf(gmId)).to.equal(1);
});
it("If transferring an attached Node to a new owner, past donated B3TR should remain associated with the GM and not be lost", async function () {
// Bootstrap emissions
await (0, common_1.bootstrapEmissions)();
// Should be able to free mint after participating in allocation voting
await (0, common_1.participateInAllocationVoting)(owner, false, otherAccounts[10]);
//Set max level of GM to 10
await galaxyMember.connect(owner).setMaxLevel(10);
//Get stargate node
const nodeId = await (0, helpers_1.createNodeHolder)(7, owner);
// Mint GM to owner
await galaxyMember.connect(owner).freeMint();
const gmId = await galaxyMember.tokenOfOwnerByIndex(await owner.getAddress(), 0);
//Attach node to GM
await galaxyMember.connect(owner).attachNode(nodeId, gmId);
//Should be attached and in Saturn level
(0, chai_1.expect)(await galaxyMember.getNodeIdAttached(gmId)).to.equal(nodeId); //Should be attached
(0, chai_1.expect)(await galaxyMember.levelOf(gmId)).to.equal(7); //Should be in Saturn level
//Pay for the upgrade to level 8
const amountToUpgrade = await galaxyMember.getB3TRtoUpgrade(gmId);
await b3tr.connect(minterAccount).mint(owner, amountToUpgrade); // Mint B3TR to owner
await b3tr.connect(owner).approve(await galaxyMember.getAddress(), amountToUpgrade); // Approve galaxyMember to transfer B3TR
await galaxyMember.connect(owner).upgrade(gmId);
//Should have donated B3TR
(0, chai_1.expect)(await galaxyMember.getB3TRdonated(gmId)).to.equal(amountToUpgrade);
//Check the new level
(0, chai_1.expect)(await galaxyMember.levelOf(gmId)).to.equal(8);
//Transfer node to otherAccount
await stargateNftMock.connect(owner).transferFrom(owner.address, otherAccount.address, nodeId);
//Expect attachment to be reset and GM downgraded
(0, chai_1.expect)(await galaxyMember.getNodeIdAttached(gmId)).to.equal(0);
//Since it has donated from level 7 to 8 , it donated 2.500.000 B3TR, so removing the node it should be downgraded to level 7
(0, chai_1.expect)(await galaxyMember.levelOf(gmId)).to.equal(7);
//Expect B3TR to remain associated with the GM
(0, chai_1.expect)(await galaxyMember.getB3TRdonated(gmId)).to.equal(amountToUpgrade);
});
it("If unstaking/burning stargate node, past donated B3TR should remain associated with the GM and not be lost", async function () {
// Bootstrap emissions
await (0, common_1.bootstrapEmissions)();
// Should be able to free mint after participating in allocation voting
await (0, common_1.participateInAllocationVoting)(owner, false, otherAccounts[10]);
//Set max level of GM to 10
await galaxyMember.connect(owner).setMaxLevel(10);
//Get stargate node
const nodeId = await (0, helpers_1.createNodeHolder)(7, owner);
// Mint GM to owner
await galaxyMember.connect(owner).freeMint();
const gmId = await galaxyMember.tokenOfOwnerByIndex(await owner.getAddress(), 0);
//Attach node to GM
await galaxyMember.connect(owner).attachNode(nodeId, gmId);
//Should be attached and in Saturn level
(0, chai_1.expect)(await galaxyMember.getNodeIdAttached(gmId)).to.equal(nodeId); //Should be attached
(0, chai_1.expect)(await galaxyMember.levelOf(gmId)).to.equal(7); //Should be in Saturn level
//Pay for the upgrade to level 8
const amountToUpgrade = await galaxyMember.getB3TRtoUpgrade(gmId);
await b3tr.connect(minterAccount).mint(owner, amountToUpgrade); // Mint B3TR to owner
await b3tr.connect(owner).approve(await galaxyMember.getAddress(), amountToUpgrade); // Approve galaxyMember to transfer B3TR
await galaxyMember.connect(owner).upgrade(gmId);
//Should have donated B3TR
(0, chai_1.expect)(await galaxyMember.getB3TRdonated(gmId)).to.equal(amountToUpgrade);
//Check the new level
(0, chai_1.expect)(await galaxyMember.levelOf(gmId)).to.equal(8);
//Unstake/burn node
await stargateMock.connect(owner).unstake(nodeId);
//Expect attachment to be reset and GM downgraded
(0, chai_1.expect)(await galaxyMember.getNodeIdAttached(gmId)).to.equal(0);
//Since it has donated from level 7 to 8 , it donated 2.500.000 B3TR, so removing the node it should be downgraded to level 7
(0, chai_1.expect)(await galaxyMember.levelOf(gmId)).to.equal(7);
//Expect B3TR to remain associated with the GM
(0, chai_1.expect)(await galaxyMember.getB3TRdonated(gmId)).to.equal(amountToUpgrade);
});
it("If unstaking/burning stargate node, gm detects as dettached and can be attached to a new node", async function () {
// Bootstrap emissions
await (0, common_1.bootstrapEmissions)();
// Should be able to free mint after participating in allocation voting
await (0, common_1.participateInAllocationVoting)(owner, false, otherAccounts[10]);
//Set max level of GM to 10
await galaxyMember.connect(owner).setMaxLevel(10);
//Get stargate node
const nodeId = await (0, helpers_1.createNodeHolder)(7, owner);
// Mint GM to owner
await galaxyMember.connect(owner).freeMint();
const gmId = await galaxyMember.tokenOfOwnerByIndex(await owner.getAddress(), 0);
//Attach node to GM
await galaxyMember.connect(owner).attachNode(nodeId, gmId);
//Unstake/burn node
await stargateMock.connect(owner).unstake(nodeId);
//Expect attachment to be reset and GM downgraded
(0, chai_1.expect)(await galaxyMember.getNodeIdAttached(gmId)).to.equal(0);
(0, chai_1.expect)(await galaxyMember.levelOf(gmId)).to.equal(1);
const newNodeId = await (0, helpers_1.createNodeHolder)(7, owner);
//Attach node to GM
await galaxyMember.connect(owner).attachNode(newNodeId, gmId);
//Expect attachment to be attached and level to be the same
(0, chai_1.expect)(await galaxyMember.getNodeIdAttached(gmId)).to.equal(newNodeId);
(0, chai_1.expect)(await galaxyMember.levelOf(gmId)).to.equal(7);
});
});