How to use createRealm method in wpt

Best JavaScript code snippet using wpt

HyperVIBES.spec.ts

Source:HyperVIBES.spec.ts Github

copy

Full Screen

...80 it("should snap on the dot sol", async function () {81 expect(await hv.name()).equals("HyperVIBES");82 });83 it("should return 0 for currentMinedTokens if invalid NFT", async () => {84 await hv.createRealm({ ...createRealm(), infusers: [a0] });85 expect(86 await hv.currentMinedTokens("1", collection.address, "12345")87 ).to.equal(0);88 });89 it("should return 0 for currentMinedTokens if non-infused NFT", async () => {90 await hv.createRealm({ ...createRealm(), infusers: [a0] });91 await collection.mint("12345");92 expect(93 await hv.currentMinedTokens("1", collection.address, "12345")94 ).to.equal(0);95 });96 it("should revert if calling currentMinedTokens for an invalid realm", async () => {97 await expect(98 hv.currentMinedTokens("1", collection.address, "12345")99 ).to.be.revertedWith("invalid realm");100 });101 });102 // ---103 // admin104 // ---105 describe("realm administration", () => {106 it("should create a realm", async () => {107 await hv.createRealm(createRealm());108 expect((await hv.realmConfig("1")).token).equals(token.address);109 });110 it("should revert if minClaimAmount is greater than maxTokenBalance", async () => {111 const create = createRealm();112 create.config.constraints.maxTokenBalance = parseUnits("1000");113 create.config.constraints.minClaimAmount = parseUnits("1001");114 await expect(hv.createRealm(create)).to.be.revertedWith(115 "invalid min claim amount"116 );117 });118 it("should revert if max token balance is zero", async () => {119 const create = createRealm();120 create.config.constraints.maxTokenBalance = BigNumber.from(0);121 await expect(hv.createRealm(create)).to.be.revertedWith(122 "invalid max token balance"123 );124 });125 it("should revert if attempting to modify a realm as a non-admin", async () => {126 await hv.createRealm(createRealm());127 await expect(hv.modifyRealm(modifyRealm())).to.be.revertedWith(128 "not realm admin"129 );130 });131 it("should revert if attempting to modify a non-existant realm", async () => {132 await hv.createRealm(createRealm());133 await expect(134 hv.modifyRealm({ ...modifyRealm(), realmId: "420" })135 ).to.be.revertedWith("invalid realm");136 });137 it("should revert if providing zero address for realm erc20", async () => {138 await expect(139 hv.createRealm({140 ...createRealm(),141 config: { ...createRealm().config, token: AddressZero },142 })143 ).to.be.revertedWith("invalid token");144 });145 it("should autoincrement realm id", async () => {146 await hv.createRealm(createRealm());147 await hv.createRealm(createRealm());148 expect((await hv.realmConfig("1")).token).equals(token.address);149 expect((await hv.realmConfig("2")).token).equals(token.address);150 });151 it("should emit a RealmCreated event on realm create", async () => {152 await expect(hv.createRealm(createRealm()))153 .to.emit(hv, "RealmCreated")154 .withArgs("1", "test realm", "description");155 });156 it("should add initial admins to realm", async () => {157 await hv.createRealm({158 ...createRealm(),159 admins: [a1, a2],160 });161 expect(await hv.isAdmin("1", a1)).to.equal(true);162 expect(await hv.isAdmin("1", a2)).to.equal(true);163 expect(await hv.isAdmin("1", a3)).to.equal(false);164 });165 it("should add initial infusers to realm", async () => {166 await hv.createRealm({167 ...createRealm(),168 infusers: [a1, a2],169 });170 expect(await hv.isInfuser("1", a1)).to.equal(true);171 expect(await hv.isInfuser("1", a2)).to.equal(true);172 expect(await hv.isInfuser("1", a3)).to.equal(false);173 });174 it("should add initial claimers to realm", async () => {175 await hv.createRealm({176 ...createRealm(),177 claimers: [a1, a2],178 });179 expect(await hv.isClaimer("1", a1)).to.equal(true);180 expect(await hv.isClaimer("1", a2)).to.equal(true);181 expect(await hv.isClaimer("1", a3)).to.equal(false);182 });183 it("should add initial collections to realm", async () => {184 await hv.createRealm({185 ...createRealm(),186 collections: [collection.address],187 });188 expect(await hv.isCollection("1", collection.address)).to.equal(true);189 });190 it("should add admins via modifyRealm", async () => {191 await hv.createRealm({ ...createRealm(), admins: [a0] });192 await hv.modifyRealm({193 ...modifyRealm(),194 adminsToAdd: [a1],195 });196 expect(await hv.isAdmin("1", a1)).to.equal(true);197 });198 it("should remove admins via modifyRealm", async () => {199 await hv.createRealm({ ...createRealm(), admins: [a0] });200 await hv.modifyRealm({201 ...modifyRealm(),202 adminsToRemove: [a0],203 });204 expect(await hv.isAdmin("1", a0)).to.equal(false);205 });206 it("should add infusers via modifyRealm", async () => {207 await hv.createRealm({ ...createRealm(), admins: [a0] });208 await hv.modifyRealm({209 ...modifyRealm(),210 infusersToAdd: [a1],211 });212 expect(await hv.isInfuser("1", a1)).to.equal(true);213 });214 it("should remove infusers via modifyRealm", async () => {215 await hv.createRealm({216 ...createRealm(),217 admins: [a0],218 infusers: [a1],219 });220 expect(await hv.isInfuser("1", a1)).to.equal(true);221 await hv.modifyRealm({222 ...modifyRealm(),223 infusersToRemove: [a1],224 });225 expect(await hv.isInfuser("1", a0)).to.equal(false);226 });227 it("should add claimers via modifyRealm", async () => {228 await hv.createRealm({ ...createRealm(), admins: [a0] });229 await hv.modifyRealm({230 ...modifyRealm(),231 claimersToAdd: [a1],232 });233 expect(await hv.isClaimer("1", a1)).to.equal(true);234 });235 it("should remove claimers via modifyRealm", async () => {236 await hv.createRealm({237 ...createRealm(),238 admins: [a0],239 claimers: [a1],240 });241 expect(await hv.isClaimer("1", a1)).to.equal(true);242 await hv.modifyRealm({243 ...modifyRealm(),244 claimersToRemove: [a1],245 });246 expect(await hv.isClaimer("1", a0)).to.equal(false);247 });248 it("should add collections via modifyRealm", async () => {249 await hv.createRealm({ ...createRealm(), admins: [a0] });250 await hv.modifyRealm({251 ...modifyRealm(),252 collectionsToAdd: [collection.address],253 });254 expect(await hv.isCollection("1", collection.address)).to.equal(true);255 });256 it("should remove collections via modifyRealm", async () => {257 await hv.createRealm({258 ...createRealm(),259 admins: [a0],260 collections: [collection.address],261 });262 expect(await hv.isCollection("1", collection.address)).to.equal(true);263 await hv.modifyRealm({264 ...modifyRealm(),265 collectionsToRemove: [collection.address],266 });267 expect(await hv.isCollection("1", collection.address)).to.equal(false);268 });269 it("should emit an AdminAdded event on modifyRealm", async () => {270 await hv.createRealm({ ...createRealm(), admins: [a0] });271 await expect(hv.modifyRealm({ ...modifyRealm(), adminsToAdd: [a1] }))272 .to.emit(hv, "AdminAdded")273 .withArgs("1", a1);274 });275 it("should emit an AdminRemoved event on modifyRealm", async () => {276 await hv.createRealm({ ...createRealm(), admins: [a0] });277 await expect(hv.modifyRealm({ ...modifyRealm(), adminsToRemove: [a0] }))278 .to.emit(hv, "AdminRemoved")279 .withArgs("1", a0);280 });281 it("should emit an InfuserAdded event on modifyRealm", async () => {282 await hv.createRealm({ ...createRealm(), admins: [a0] });283 await expect(hv.modifyRealm({ ...modifyRealm(), infusersToAdd: [a1] }))284 .to.emit(hv, "InfuserAdded")285 .withArgs("1", a1);286 });287 it("should emit an InfuserRemoved event on modifyRealm", async () => {288 await hv.createRealm({ ...createRealm(), admins: [a0] });289 await expect(hv.modifyRealm({ ...modifyRealm(), infusersToRemove: [a0] }))290 .to.emit(hv, "InfuserRemoved")291 .withArgs("1", a0);292 });293 it("should emit an ClaimerAdded event on modifyRealm", async () => {294 await hv.createRealm({ ...createRealm(), admins: [a0] });295 await expect(hv.modifyRealm({ ...modifyRealm(), claimersToAdd: [a1] }))296 .to.emit(hv, "ClaimerAdded")297 .withArgs("1", a1);298 });299 it("should emit an ClaimerRemoved event on modifyRealm", async () => {300 await hv.createRealm({ ...createRealm(), admins: [a0] });301 await expect(hv.modifyRealm({ ...modifyRealm(), claimersToRemove: [a0] }))302 .to.emit(hv, "ClaimerRemoved")303 .withArgs("1", a0);304 });305 it("should emit a CollectionAdded event on modifyRealm", async () => {306 await hv.createRealm({ ...createRealm(), admins: [a0] });307 await expect(308 hv.modifyRealm({309 ...modifyRealm(),310 collectionsToAdd: [collection.address],311 })312 )313 .to.emit(hv, "CollectionAdded")314 .withArgs("1", collection.address);315 });316 it("should emit an CollectionRemoved event on modifyRealm", async () => {317 await hv.createRealm({ ...createRealm(), admins: [a0] });318 await expect(319 hv.modifyRealm({320 ...modifyRealm(),321 collectionsToRemove: [collection.address],322 })323 )324 .to.emit(hv, "CollectionRemoved")325 .withArgs("1", collection.address);326 });327 it("should revert when adding or removing entities with zero address", async () => {328 await hv.createRealm({ ...createRealm(), admins: [a0] });329 await expect(330 hv.modifyRealm({ ...modifyRealm(), adminsToAdd: [AddressZero] })331 ).to.be.revertedWith("invalid admin");332 await expect(333 hv.modifyRealm({ ...modifyRealm(), adminsToRemove: [AddressZero] })334 ).to.be.revertedWith("invalid admin");335 await expect(336 hv.modifyRealm({ ...modifyRealm(), infusersToAdd: [AddressZero] })337 ).to.be.revertedWith("invalid infuser");338 await expect(339 hv.modifyRealm({ ...modifyRealm(), infusersToRemove: [AddressZero] })340 ).to.be.revertedWith("invalid infuser");341 await expect(342 hv.modifyRealm({ ...modifyRealm(), claimersToAdd: [AddressZero] })343 ).to.be.revertedWith("invalid claimer");344 await expect(345 hv.modifyRealm({ ...modifyRealm(), claimersToRemove: [AddressZero] })346 ).to.be.revertedWith("invalid claimer");347 await expect(348 hv.modifyRealm({ ...modifyRealm(), collectionsToAdd: [AddressZero] })349 ).to.be.revertedWith("invalid collection");350 await expect(351 hv.modifyRealm({352 ...modifyRealm(),353 collectionsToRemove: [AddressZero],354 })355 ).to.be.revertedWith("invalid collection");356 });357 });358 // ---359 // end-users360 // ---361 describe("infusion", () => {362 // ---363 // fixtures364 // ---365 const infuse = () => {366 return {367 realmId: "1",368 collection: collection.address,369 tokenId: "420",370 infuser: a0,371 amount: parseUnits("50000"),372 comment: "comment",373 };374 };375 // ---376 // tests377 // ---378 it("should infuse tokens from msg.sender to nft", async () => {379 await hv.createRealm({ ...createRealm(), infusers: [a0] });380 await token.mint(parseUnits("60000"));381 await collection.mint("420");382 await hv.infuse({ ...infuse() });383 expect(await token.balanceOf(a0)).to.equal(parseUnits("10000"));384 expect(385 (await hv.tokenData("1", collection.address, "420")).balance386 ).to.equal(parseUnits("50000"));387 expect(await token.balanceOf(hv.address)).to.equal(parseUnits("50000"));388 });389 it("should batch infuse tokens from msg.sender to nft", async () => {390 await hv.createRealm({ ...createRealm(), infusers: [a0] });391 await token.mint(parseUnits("1000000"));392 const tokenIds = [...new Array(100)].map((_, idx) => `${idx + 1}`);393 for (const tokenId of tokenIds) {394 await collection.mint(tokenId);395 }396 await hv.batchInfuse(397 tokenIds.map((tokenId) => {398 return {399 amount: parseUnits("1000"),400 collection: collection.address,401 comment: "",402 infuser: a0,403 realmId: "1",404 tokenId,405 };406 })407 );408 expect(await token.balanceOf(a0)).to.equal(parseUnits("900000"));409 expect(410 (await hv.tokenData("1", collection.address, "1")).balance411 ).to.equal(parseUnits("1000"));412 expect(await token.balanceOf(hv.address)).to.equal(parseUnits("100000"));413 });414 it("should clamp infused amount to to max token balance", async () => {415 await token.mint(parseUnits("100000"));416 await collection.mint("420");417 const create = createRealm();418 create.config.constraints.maxTokenBalance = parseUnits("60000");419 create.config.constraints.allowPublicInfusion = true;420 await hv.createRealm(create);421 await hv.infuse({ ...infuse(), amount: parseUnits("100000") });422 expect(await token.balanceOf(a0)).to.equal(parseUnits("40000")); // only took 60000423 expect(424 (await hv.tokenData("1", collection.address, "420")).balance425 ).to.equal(parseUnits("60000"));426 });427 it("should handle multi infusion", async () => {428 await token.mint(parseUnits("100000"));429 await collection.mint("420");430 const create = { ...createRealm(), infusers: [a0] };431 create.config.constraints.allowMultiInfuse = true;432 await hv.createRealm(create);433 await hv.infuse({ ...infuse(), amount: parseUnits("1000") });434 await hv.infuse({ ...infuse(), amount: parseUnits("1000") });435 await hv.infuse({ ...infuse(), amount: parseUnits("1000") });436 expect(await token.balanceOf(a0)).to.equal(parseUnits("97000"));437 expect(438 (await hv.tokenData("1", collection.address, "420")).balance439 ).to.equal(parseUnits("3000"));440 });441 it("should emit an Infused event", async () => {442 await token.mint(parseUnits("100000"));443 await collection.mint("420");444 const create = { ...createRealm(), infusers: [a0] };445 await hv.createRealm(create);446 await expect(hv.infuse({ ...infuse(), amount: parseUnits("1000") }))447 .to.emit(hv, "Infused")448 .withArgs(449 "1",450 collection.address,451 "420",452 a0,453 parseUnits("1000"),454 "comment"455 );456 });457 it("should revert on an invalid token id", async () => {458 await token.mint(parseUnits("100000"));459 const create = { ...createRealm(), infusers: [a0] };460 await hv.createRealm(create);461 await expect(hv.infuse(infuse())).to.revertedWith("invalid token");462 });463 it("should revert on an invalid token contract", async () => {464 await token.mint(parseUnits("100000"));465 const create = { ...createRealm(), infusers: [a0] };466 await hv.createRealm(create);467 await expect(468 hv.infuse({ ...infuse(), collection: token.address })469 ).to.be.revertedWith("invalid token");470 });471 it("should revert on an invalid realm", async () => {472 await token.mint(parseUnits("100000"));473 await collection.mint("420");474 const create = { ...createRealm(), infusers: [a0] };475 await hv.createRealm(create);476 await expect(477 hv.infuse({ ...infuse(), realmId: "123" })478 ).to.be.revertedWith("invalid realm");479 });480 it("should revert if amount is too low", async () => {481 await token.mint(parseUnits("100000"));482 await collection.mint("420");483 const create = { ...createRealm(), infusers: [a0] };484 create.config.constraints.minInfusionAmount = parseUnits("1000");485 await hv.createRealm(create);486 await expect(487 hv.infuse({ ...infuse(), amount: parseUnits("10") })488 ).to.be.revertedWith("amount too low");489 });490 it("should revert if nft not owned by infuser and requireNftIsOwned is true", async () => {491 await token.mint(parseUnits("100000"));492 await collection.mint("420");493 await collection.transferFrom(a0, a1, "420");494 const create = { ...createRealm(), infusers: [a0] };495 create.config.constraints.requireNftIsOwned = true;496 await hv.createRealm(create);497 await expect(hv.infuse({ ...infuse() })).to.be.revertedWith(498 "nft not owned by infuser"499 );500 });501 it("should revert if attempting proxy infusion by non-proxy", async () => {502 await token.mint(parseUnits("100000"));503 await collection.mint("420");504 await collection.transferFrom(a0, a1, "420");505 const create = { ...createRealm(), infusers: [a0] };506 await hv.createRealm(create);507 await expect(hv.infuse({ ...infuse(), infuser: a1 })).to.be.revertedWith(508 "invalid proxy"509 );510 });511 it("should revert if attempting proxy infusion by non-proxy thats on the allowlist", async () => {512 await token.mint(parseUnits("100000"));513 await collection.mint("420");514 await collection.transferFrom(a0, a1, "420");515 const create = { ...createRealm(), infusers: [a0, a1] };516 await hv.createRealm(create);517 await expect(hv.infuse({ ...infuse(), infuser: a1 })).to.be.revertedWith(518 "invalid proxy"519 );520 });521 it("should revert if attempting public infusion when allowPublicInfusion is false", async () => {522 await token.mint(parseUnits("100000"));523 await collection.mint("420");524 const create = { ...createRealm(), infusers: [] };525 await hv.createRealm(create);526 await expect(hv.infuse({ ...infuse() })).to.be.revertedWith(527 "invalid infuser"528 );529 });530 it("should allow public infusions when allowPublicInfusion flag is true", async () => {531 await token.mint(parseUnits("100000"));532 await collection.mint("420");533 const create = { ...createRealm(), infusers: [] };534 create.config.constraints.allowPublicInfusion = true;535 await hv.createRealm(create);536 await hv.infuse({ ...infuse(), amount: parseUnits("1000") });537 expect(await token.balanceOf(a0)).to.equal(parseUnits("99000"));538 expect(539 (await hv.tokenData("1", collection.address, "420")).balance540 ).to.equal(parseUnits("1000"));541 });542 it("should revert if infusing a non-allowed collection and allowAllCollections is false", async () => {543 await token.mint(parseUnits("100000"));544 await collection.mint("420");545 const create = { ...createRealm(), infusers: [a0], collection: [] };546 create.config.constraints.allowAllCollections = false;547 await hv.createRealm(create);548 await expect(hv.infuse(infuse())).to.be.revertedWith(549 "invalid collection"550 );551 });552 it("should revert if infusing a second time when allowMultiInfuse is false", async () => {553 await token.mint(parseUnits("100000"));554 await collection.mint("420");555 const create = { ...createRealm(), infusers: [a0] };556 create.config.constraints.allowMultiInfuse = false;557 await hv.createRealm(create);558 await hv.infuse({ ...infuse(), amount: parseUnits("1000") });559 await expect(560 hv.infuse({ ...infuse(), amount: parseUnits("1000") })561 ).to.be.revertedWith("multi infuse disabled");562 });563 it("should revert if clamped infusion amount is zero on multi-infuse", async () => {564 await token.mint(parseUnits("100000"));565 await collection.mint("420");566 const create = { ...createRealm(), infusers: [a0] };567 create.config.constraints.maxTokenBalance = parseUnits("10000");568 create.config.constraints.allowMultiInfuse = true;569 await hv.createRealm(create);570 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });571 await expect(572 hv.infuse({ ...infuse(), amount: parseUnits("10000") })573 ).to.be.revertedWith("nothing to transfer");574 });575 it("should revert if clamped infusion amount is less than min infusion amount", async () => {576 await token.mint(parseUnits("100000"));577 await collection.mint("420");578 const create = { ...createRealm(), infusers: [a0] };579 create.config.constraints.maxTokenBalance = parseUnits("10000");580 create.config.constraints.allowMultiInfuse = true;581 create.config.constraints.minInfusionAmount = parseUnits("1000");582 await hv.createRealm(create);583 await hv.infuse({ ...infuse(), amount: parseUnits("9999") });584 await expect(585 hv.infuse({ ...infuse(), amount: parseUnits("10000") })586 ).to.be.revertedWith("amount too low");587 });588 });589 describe("infusion proxy management", () => {590 it("should emit an ProxyAdded event when adding a proxy", async () => {591 await hv.createRealm(createRealm());592 await expect(hv.allowProxy("1", a1))593 .to.emit(hv, "ProxyAdded")594 .withArgs("1", a1);595 });596 it("should emit an ProxyRemoved event when removing a proxy", async () => {597 await hv.createRealm(createRealm());598 await expect(hv.denyProxy("1", a1))599 .to.emit(hv, "ProxyRemoved")600 .withArgs("1", a1);601 });602 it("should revert if providing an invalid realm to allowProxy", async () => {603 await expect(hv.allowProxy("1", a1)).to.be.revertedWith("invalid realm");604 });605 it("should revert if providing an invalid realm to denyProxy", async () => {606 await expect(hv.denyProxy("1", a1)).to.be.revertedWith("invalid realm");607 });608 });609 describe("claiming", () => {610 // ---611 // fixtures612 // ---613 const infuse = () => {614 return {615 realmId: "1",616 collection: collection.address,617 tokenId: "420",618 infuser: a0,619 amount: parseUnits("10000"),620 comment: "comment",621 };622 };623 const claim = () => {624 return {625 realmId: "1",626 collection: collection.address,627 tokenId: "420",628 amount: parseUnits("100000"), // all629 };630 };631 const mineNextBlock = () => ethers.provider.send("evm_mine", []);632 const setAutomine = (set = true) =>633 ethers.provider.send("evm_setAutomine", [set]);634 const increaseTimestampAndMineNextBlock = async (635 offsetInSeconds: number636 ) => {637 await ethers.provider.send("evm_increaseTime", [offsetInSeconds]);638 await mineNextBlock();639 };640 beforeEach(() => setAutomine(false));641 afterEach(() => setAutomine(true));642 // ---643 // tests644 // ---645 it("should claim tokens", async () => {646 await hv.createRealm({ ...createRealm(), infusers: [a0] });647 await token.mint(parseUnits("10000"));648 await collection.mint("420");649 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });650 await mineNextBlock();651 // jump 1 day652 await increaseTimestampAndMineNextBlock(60 * 60 * 24);653 await hv.claim({ ...claim(), amount: parseUnits("1000") });654 await mineNextBlock();655 expect(await token.balanceOf(a0)).to.equal(parseUnits("1000"));656 // jump 1 day657 await increaseTimestampAndMineNextBlock(60 * 60 * 24);658 await hv.claim({ ...claim(), amount: parseUnits("1000") });659 await mineNextBlock();660 expect(await token.balanceOf(a0)).to.equal(parseUnits("2000"));661 // jump 100 days662 await increaseTimestampAndMineNextBlock(60 * 60 * 24 * 100);663 await hv.claim({ ...claim(), amount: parseUnits("10000") });664 await mineNextBlock();665 expect(await token.balanceOf(a0)).to.equal(parseUnits("10000"));666 });667 it("should allow valid proxies to claim on behalf of owner", async () => {668 const hv1 = hv.connect(accounts[1]);669 await hv.createRealm({ ...createRealm(), infusers: [a0] });670 await hv.allowProxy("1", a1);671 await token.mint(parseUnits("10000"));672 await collection.mint("420");673 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });674 await mineNextBlock();675 // jump 1 day676 await increaseTimestampAndMineNextBlock(60 * 60 * 24);677 await hv1.claim({ ...claim(), amount: parseUnits("1000") });678 await mineNextBlock();679 expect(await token.balanceOf(a0)).to.equal(parseUnits("0"));680 expect(await token.balanceOf(a1)).to.equal(parseUnits("1000"));681 });682 it("should revert if proxy claim is made when allow public claims is false if not on allowlist", async () => {683 const hv1 = hv.connect(accounts[1]);684 const create = { ...createRealm(), infusers: [a0] };685 create.config.constraints.allowPublicClaiming = false;686 await hv.createRealm(create);687 await hv.allowProxy("1", a1);688 await token.mint(parseUnits("10000"));689 await collection.mint("420");690 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });691 await mineNextBlock();692 // jump 1 day693 await increaseTimestampAndMineNextBlock(60 * 60 * 24);694 setAutomine(true);695 await expect(696 hv1.claim({ ...claim(), amount: parseUnits("1000") })697 ).to.be.revertedWith("invalid claimer");698 });699 it("should revert if allowlist proxy claim is made but proxy was not approved", async () => {700 const hv1 = hv.connect(accounts[1]);701 const create = { ...createRealm(), infusers: [a0], claimers: [a1] };702 create.config.constraints.allowPublicClaiming = false;703 await hv.createRealm(create);704 await token.mint(parseUnits("10000"));705 await collection.mint("420");706 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });707 await mineNextBlock();708 // jump 1 day709 await increaseTimestampAndMineNextBlock(60 * 60 * 24);710 setAutomine(true);711 await expect(712 hv1.claim({ ...claim(), amount: parseUnits("1000") })713 ).to.be.revertedWith("invalid claimer");714 });715 it("should allow claimers to claim on behalf if authorized proxy and no self claim", async () => {716 const hv1 = hv.connect(accounts[1]);717 const create = { ...createRealm(), infusers: [a0], claimers: [a1] };718 create.config.constraints.allowPublicClaiming = false;719 await hv.createRealm(create);720 await hv.allowProxy("1", a1);721 await token.mint(parseUnits("10000"));722 await collection.mint("420");723 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });724 await mineNextBlock();725 // jump 1 day726 await increaseTimestampAndMineNextBlock(60 * 60 * 24);727 await hv1.claim({ ...claim(), amount: parseUnits("1000") });728 await mineNextBlock();729 expect(await token.balanceOf(a0)).to.equal(parseUnits("0"));730 expect(await token.balanceOf(a1)).to.equal(parseUnits("1000"));731 });732 it("should batch claim tokens", async () => {733 await setAutomine();734 await hv.createRealm({ ...createRealm(), infusers: [a0] });735 await token.mint(parseUnits("100000"));736 const tokenIds = [...new Array(100)].map((_, idx) => `${idx + 1}`);737 for (const tokenId of tokenIds) {738 await collection.mint(tokenId);739 }740 await hv.batchInfuse(741 tokenIds.map((tokenId) => {742 return {743 amount: parseUnits("1000"),744 collection: collection.address,745 comment: "",746 infuser: a0,747 realmId: "1",748 tokenId,749 };750 })751 );752 // jump 1 day753 await increaseTimestampAndMineNextBlock(60 * 60 * 24);754 await hv.batchClaim(755 tokenIds.map((tokenId) => {756 return {757 amount: parseUnits("1000"),758 collection: collection.address,759 realmId: "1",760 tokenId,761 };762 })763 );764 expect(await token.balanceOf(a0)).to.equal(parseUnits("100000"));765 expect(await token.balanceOf(hv.address)).to.equal(parseUnits("0"));766 });767 it("should emit a Claimed event on claim", async () => {768 await setAutomine();769 await hv.createRealm({ ...createRealm(), infusers: [a0] });770 await token.mint(parseUnits("10000"));771 await collection.mint("420");772 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });773 await increaseTimestampAndMineNextBlock(60 * 60 * 24);774 await expect(hv.claim({ ...claim(), amount: parseUnits("1000") }))775 .to.emit(hv, "Claimed")776 .withArgs("1", collection.address, "420", parseUnits("1000"));777 });778 it("should revert if nothing to claim", async () => {779 await setAutomine();780 await hv.createRealm({ ...createRealm(), infusers: [a0] });781 await token.mint(parseUnits("10000"));782 await collection.mint("420");783 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });784 await increaseTimestampAndMineNextBlock(60 * 60 * 24 * 1000);785 await hv.claim({ ...claim(), amount: parseUnits("10000") }); // claim all786 await expect(787 hv.claim({ ...claim(), amount: parseUnits("10000") })788 ).to.be.revertedWith("nothing to claim");789 });790 it("should revert if not token owner", async () => {791 await setAutomine();792 await hv.createRealm({ ...createRealm(), infusers: [a0] });793 await token.mint(parseUnits("10000"));794 await collection.mint("420");795 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });796 await increaseTimestampAndMineNextBlock(60 * 60 * 24 * 1000);797 const hv1 = hv.connect(accounts[1]);798 await expect(799 hv1.claim({ ...claim(), amount: "10000" })800 ).to.be.revertedWith("invalid claimer");801 });802 it("should revert if owned but public claiming is disabled", async () => {803 await setAutomine();804 const create = { ...createRealm(), infusers: [a0] };805 create.config.constraints.allowPublicClaiming = false;806 await hv.createRealm(create);807 await token.mint(parseUnits("10000"));808 await collection.mint("420");809 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });810 await increaseTimestampAndMineNextBlock(60 * 60 * 24 * 1000);811 await expect(812 hv.claim({ ...claim(), amount: parseUnits("1000") })813 ).to.be.revertedWith("invalid claimer");814 });815 it("should revert if approved but public claiming is disabled", async () => {816 await setAutomine();817 const create = { ...createRealm(), infusers: [a0] };818 create.config.constraints.allowPublicClaiming = false;819 await hv.createRealm(create);820 await token.mint(parseUnits("10000"));821 await collection.mint("420");822 await collection.approve(a1, "420"); // <-- a1 approved for token823 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });824 await increaseTimestampAndMineNextBlock(60 * 60 * 24 * 1000);825 const hv1 = hv.connect(accounts[1]);826 await expect(827 hv1.claim({ ...claim(), amount: parseUnits("1000") })828 ).to.be.revertedWith("invalid claimer");829 });830 it("should revert if attempting to claim from un-infused token", async () => {831 await setAutomine();832 await hv.createRealm({ ...createRealm(), infusers: [a0] });833 await token.mint(parseUnits("10000"));834 await collection.mint("420");835 await increaseTimestampAndMineNextBlock(60 * 60 * 24 * 1000);836 await expect(hv.claim({ ...claim() })).to.be.revertedWith(837 "token not infused"838 );839 });840 it("should revert if claiming less than minClaimAmount", async () => {841 await setAutomine();842 const create = { ...createRealm(), infusers: [a0] };843 create.config.constraints.minClaimAmount = parseUnits("1000");844 await hv.createRealm(create);845 await token.mint(parseUnits("10000"));846 await collection.mint("420");847 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });848 await increaseTimestampAndMineNextBlock(60 * 60 * 24 * 1000);849 await expect(850 hv.claim({ ...claim(), amount: parseUnits("50") })851 ).to.be.revertedWith("amount too low");852 });853 it("should revert if claiming less than minClaimAmount when amount is gt token balance", async () => {854 await setAutomine();855 const create = { ...createRealm(), infusers: [a0] };856 create.config.constraints.minClaimAmount = parseUnits("1000");857 await hv.createRealm(create);858 await token.mint(parseUnits("10000"));859 await collection.mint("420");860 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });861 await increaseTimestampAndMineNextBlock(60 * 60);862 await expect(863 hv.claim({ ...claim(), amount: parseUnits("100000") })864 ).to.be.revertedWith("amount too low");865 });866 it("should only claim one day of tokens after one day", async () => {867 await hv.createRealm({ ...createRealm(), infusers: [a0] });868 await token.mint(parseUnits("10000"));869 await collection.mint("420");870 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });871 await mineNextBlock();872 // jump 1 day873 await hv.claim({ ...claim(), amount: parseUnits("100000") }); // attempt overclaim874 await increaseTimestampAndMineNextBlock(60 * 60 * 24);875 expect(await token.balanceOf(a0)).to.equal(parseUnits("1000"));876 });877 it("should claim entire balance after tokens fully mined out", async () => {878 await hv.createRealm({ ...createRealm(), infusers: [a0] });879 await token.mint(parseUnits("10000"));880 await collection.mint("420");881 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });882 await mineNextBlock();883 // jump way forward884 await increaseTimestampAndMineNextBlock(60 * 60 * 24 * 365);885 expect(886 await hv.currentMinedTokens("1", collection.address, "420")887 ).to.equal(parseUnits("10000"));888 await hv.claim({ ...claim(), amount: parseUnits("100000") });889 await mineNextBlock();890 expect(await token.balanceOf(a0)).to.equal(parseUnits("10000"));891 });892 it("should only allow claiming newly mined tokens after re-infusing an empty nft", async () => {893 const create = { ...createRealm(), infusers: [a0] };894 create.config.constraints.allowMultiInfuse = true;895 await hv.createRealm(create);896 await token.mint(parseUnits("100000"));897 await collection.mint("420");898 await hv.infuse({899 ...infuse(),900 amount: parseUnits("10000"),901 });902 await mineNextBlock();903 // jump forward , claim all904 await hv.claim({ ...claim(), amount: parseUnits("10000") });905 await increaseTimestampAndMineNextBlock(60 * 60 * 24 * 10);906 expect(await token.balanceOf(a0)).to.equal(parseUnits("100000"));907 expect(908 (await hv.tokenData("1", collection.address, "420")).balance909 ).to.equal(parseUnits("0"));910 expect(911 await hv.currentMinedTokens("1", collection.address, "420")912 ).to.equal(parseUnits("0"));913 // jump forward alot914 await hv.infuse({915 ...infuse(),916 amount: parseUnits("100000"),917 });918 await increaseTimestampAndMineNextBlock(60 * 60 * 24 * 365);919 expect(920 await hv.currentMinedTokens("1", collection.address, "420")921 ).to.equal(parseUnits("0"));922 // jump forward 1 day , assert only 1 days worth claimable923 await hv.claim({ ...claim(), amount: parseUnits("100000") });924 await increaseTimestampAndMineNextBlock(60 * 60 * 24 * 1);925 expect(await token.balanceOf(a0)).to.equal(parseUnits("1000"));926 expect(927 (await hv.tokenData("1", collection.address, "420")).balance928 ).to.equal(parseUnits("99000"));929 expect(930 await hv.currentMinedTokens("1", collection.address, "420")931 ).to.equal(parseUnits("0"));932 });933 it("should reduce claimable following a claim", async () => {934 await hv.createRealm({ ...createRealm(), infusers: [a0] });935 await token.mint(parseUnits("10000"));936 await collection.mint("420");937 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });938 await mineNextBlock();939 // jump 1 day940 await hv.claim({ ...claim(), amount: parseUnits("1000") });941 await increaseTimestampAndMineNextBlock(60 * 60 * 24);942 expect(943 (await hv.tokenData("1", collection.address, "420")).balance944 ).to.equal(parseUnits("9000"));945 expect(await token.balanceOf(a0)).to.equal(parseUnits("1000"));946 });947 it("should reduce currentMinedTokens after claim", async () => {948 await hv.createRealm({ ...createRealm(), infusers: [a0] });949 await token.mint(parseUnits("10000"));950 await collection.mint("420");951 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });952 await mineNextBlock();953 // jump 1 day954 await hv.claim({ ...claim(), amount: parseUnits("100000") });955 await increaseTimestampAndMineNextBlock(60 * 60 * 24);956 expect(957 await hv.currentMinedTokens("1", collection.address, "420")958 ).to.equal(parseUnits("0"));959 });960 it("should not allow claiming immediately after claiming", async () => {961 await hv.createRealm({ ...createRealm(), infusers: [a0] });962 await token.mint(parseUnits("10000"));963 await collection.mint("420");964 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });965 await mineNextBlock();966 // jump 1 day967 await hv.claim({ ...claim(), amount: parseUnits("100000") });968 await hv.claim({ ...claim(), amount: parseUnits("100000") });969 await hv.claim({ ...claim(), amount: parseUnits("100000") });970 await hv.claim({ ...claim(), amount: parseUnits("100000") }); // several overlcaims971 await increaseTimestampAndMineNextBlock(60 * 60 * 24);972 expect(973 await hv.currentMinedTokens("1", collection.address, "420")974 ).to.equal(parseUnits("0"));975 });976 it("should handle partial claiming", async () => {977 await hv.createRealm({ ...createRealm(), infusers: [a0] });978 await token.mint(parseUnits("10000"));979 await collection.mint("420");980 await hv.infuse({ ...infuse(), amount: parseUnits("10000") });981 await mineNextBlock();982 await hv.claim({ ...claim(), amount: parseUnits("100") });983 await hv.claim({ ...claim(), amount: parseUnits("100") });984 await hv.claim({ ...claim(), amount: parseUnits("100") });985 await hv.claim({ ...claim(), amount: parseUnits("200") });986 await increaseTimestampAndMineNextBlock(60 * 60 * 24);987 expect(988 (await hv.tokenData("1", collection.address, "420")).balance989 ).to.equal(parseUnits("9500"));990 expect(await token.balanceOf(a0)).to.equal(parseUnits("500"));991 expect(992 await hv.currentMinedTokens("1", collection.address, "420")993 ).to.equal(parseUnits("500"));994 });995 it("should revert if attempting to claim from an invalid token", async () => {996 await setAutomine();997 await hv.createRealm({ ...createRealm(), infusers: [a0] });998 await expect(hv.claim({ ...claim() })).to.be.revertedWith(999 "invalid token"1000 );1001 });1002 });1003 describe("reference 721 contract", () => {1004 let ref721: ReferenceERC721;1005 beforeEach(async () => {1006 const ReferenceERC721 = await ethers.getContractFactory(1007 "ReferenceERC721"1008 );1009 ref721 = await ReferenceERC721.deploy();1010 });1011 // ---1012 // testing integration with an ERC721 that infuses on mint1013 // ---1014 it("should infuse on mint", async () => {1015 // create the realm -- this will be done via the UI1016 await hv.createRealm({1017 ...createRealm(),1018 admins: [], // no admins, keeps things safe but prevents any modifications1019 collections: [ref721.address], // only nfts from the 721 can be infused1020 infusers: [ref721.address], // only the 721 contract can infuse1021 config: {1022 ...createRealm().config,1023 constraints: {1024 ...realmConstraints(),1025 requireNftIsOwned: false, // the 721 will infuse after mint, will be in minters wallet1026 allowMultiInfuse: false, // not needed1027 allowPublicInfusion: false, // dont want anyone else infusing on this realm1028 allowAllCollections: false, // only want our 721 involved for now1029 },1030 },1031 });1032 // point the collection at hv -- needs to just be done once1033 await ref721.setHyperVIBES(token.address, "1", hv.address);1034 // stock the 721 with tokens -- need to provide (tokens per NFT * total NFT) tokens1035 await token.mint(parseUnits("300000"));1036 await token.transfer(ref721.address, parseUnits("300000"));...

Full Screen

Full Screen

index.tests.js

Source:index.tests.js Github

copy

Full Screen

...52describe('create-realm', () => {53 test('no realm fails', () => {54 expect.assertions(1)55 const request = {}56 return createRealm(request, actions)57 .catch(err => expect(err).toBe('[400] "realm" is required'))58 })59 test('no access_token fails', () => {60 expect.assertions(1)61 const request = {62 pathParameters: { realm: 'realm' },63 }64 return createRealm(request, actions)65 .catch(err => expect(err).toBe('[400] "access_token" is required'))66 })67 test('invalid access_token returns jwt malformed', () => {68 expect.assertions(2)69 const request = {70 pathParameters: { realm: 'realm' },71 body: querystring.stringify({72 access_token: 'access_token',73 })74 }75 const myActions = R.set(R.lensPath(['log', 'error']), err => {76 expect(err).toMatch(/JsonWebTokenError: jwt malformed/)77 }, actions)78 return createRealm(request, myActions)79 .catch(err => expect(err).toBe('[500] server_error'))80 })81 test('non default realm returns Not Authorized', () => {82 expect.assertions(2)83 const request = {84 pathParameters: { realm: 'mojo:default' },85 body: querystring.stringify({86 access_token: invalidRealmRefreshToken,87 })88 }89 const myActions = R.set(R.lensPath(['log', 'error']), err => {90 expect(err).toBe('Not Authorized')91 }, actions)92 return createRealm(request, myActions)93 .catch(err => expect(err).toBe('[500] server_error'))94 })95 test('invalid realm returns Not Authorized', () => {96 expect.assertions(2)97 const request = {98 pathParameters: { realm: 'mojo:default' },99 body: querystring.stringify({100 access_token: anotherUserRefreshToken,101 })102 }103 const myActions = R.set(R.lensPath(['log', 'error']), err => {104 expect(err).toBe('Not Authorized')105 }, actions)106 return createRealm(request, myActions)107 .catch(err => expect(err).toBe('[500] server_error'))108 })109 test('user doesn\'t own realm returns Not Authorized', () => {110 expect.assertions(2)111 const request = {112 pathParameters: { realm: 'mojo:default' },113 body: querystring.stringify({114 access_token: invalidRealmRefreshToken,115 })116 }117 const myActions = R.set(R.lensPath(['log', 'error']), err => {118 expect(err).toBe('Not Authorized')119 }, actions)120 return createRealm(request, myActions)121 .catch(err => expect(err).toBe('[500] server_error'))122 })123 test('realm already exists return [409] Realm already exists', () => {124 expect.assertions(1)125 const request = {126 pathParameters: { realm: 'mojo:default' },127 body: querystring.stringify({128 access_token: refreshToken,129 })130 }131 const myActions = Object.assign({}, actions, {132 createRealm: realm => Promise.reject('Realm already exists')133 })134 return createRealm(request, myActions)135 .catch(err => expect(err).toBe('[409] Realm already exists'))136 })137 test('user creates realm', () => {138 expect.assertions(1)139 const request = {140 pathParameters: { realm: 'mojo:default' },141 body: querystring.stringify({142 access_token: refreshToken,143 })144 }145 return createRealm(request, actions)146 .then(data => expect(data).toEqual({ owner: 'mojo', realmId: 'mojo:default' }))147 })...

Full Screen

Full Screen

handler.js

Source:handler.js Github

copy

Full Screen

1/* eslint-disable no-unused-vars */2const bunyan = require('bunyan')3const bformat = require('bunyan-format')4const fs = require('fs')5const callbackify = require('functional-helpers/callbackify')6const promisify = require('functional-helpers/promisify')7const token = require('./actions/token')8const authorize = require('./actions/authorize')9const openidConfiguration = require('./actions/openid-configuration')10const userRegistration = require('./actions/user-registration')11const createRealmAction = require('./actions/create-realm')12const withJsonResponse = require('./lib/serviceHelpers').withJsonResponse13const getUser = require('./services/storage').getUser14const createUser = require('./services/storage').createUser15const getRealm = require('./services/storage').getRealm16const createRealm = require('./services/storage').createRealm17const logging = require('./services/logging')18const actions = {19 getRealm,20 createRealm,21 getUser,22 createUser,23 readFile: promisify(fs.readFile),24 log: bunyan.createLogger({25 name: 'mojo-auth',26 stream: bformat({ outputMode: process.env.SLS_DEBUG ? 'short' : 'bunyan' }),27 level: 'debug'28 }),29}30module.exports.openidConfiguration = callbackify((request, context) =>31 withJsonResponse(openidConfiguration)(request, actions)32)33module.exports.token = callbackify((request, context) =>34 withJsonResponse(token)(request, actions)35)36module.exports.authorize = callbackify((request, context) =>37 withJsonResponse(authorize)(request, actions)38)39module.exports.userRegistration = callbackify((request, context) =>40 withJsonResponse(userRegistration)(request, actions)41)42module.exports.createRealm = callbackify((request, context) =>43 withJsonResponse(createRealmAction)(request, actions)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var realm = createRealm();2var global = realm.global;3var other = realm.eval("this");4assertEq(global, other);5var global = createGlobal();6var other = evalcx("", global);7assertEq(global, other);8var sandbox = createSandbox();9var global = sandbox.global;10var other = sandbox.eval("this");11assertEq(global, other);12var compartment = createCompartment();13var global = compartment.global;14var other = compartment.eval("this");15assertEq(global, other);16var world = createIsolatedWorld();17var global = world.global;18var other = world.eval("this");19assertEq(global, other);20var shell = createContentShell();21var global = shell.global;22var other = shell.eval("this");23assertEq(global, other);24var global = createFreshGlobal();25var other = evalcx("", global);26assertEq(global, other);27var window = createDOMWindow();28var global = window.window;29var other = window.eval("this");30assertEq(global, other);31var obj = createObjectIn(this);32assertEq(obj instanceof Object, true);33var obj = createObjectIn(this, {defineAs: "obj"});34assertEq(obj instanceof Object, true);35assertEq(this.obj, obj);36var array = createArrayIn(this);37assertEq(array instanceof Array, true);38var array = createArrayIn(this, {defineAs: "array"});39assertEq(array instanceof Array, true);40assertEq(this.array, array);41var wrapper = createWrapperIn(this);42assertEq(wrapper instanceof Object, true);43var wrapper = createWrapperIn(this, {defineAs: "wrapper"});

Full Screen

Using AI Code Generation

copy

Full Screen

1var realm = createRealm();2var global = realm.global;3var obj = new global.Object();4assertEq(obj instanceof global.Object, true);5assertEq(obj instanceof Object, true);6var sandbox = createSandbox();7var obj = new sandbox.Object();8assertEq(obj instanceof sandbox.Object, true);9assertEq(obj instanceof Object, true);10var global = createGlobal();11var obj = new global.Object();12assertEq(obj instanceof global.Object, true);13assertEq(obj instanceof Object, true);14var realm = createRealm();15var global = realm.global;16var obj = new global.Object();17assertEq(obj instanceof global.Object, true);18assertEq(obj instanceof Object, true);19var sandbox = createSandbox();20var obj = new sandbox.Object();21assertEq(obj instanceof sandbox.Object, true);22assertEq(obj instanceof Object, true);23var global = createGlobal();24var obj = new global.Object();25assertEq(obj instanceof global.Object, true);26assertEq(obj instanceof Object, true);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptModule = require('wptModule');2var realm = wptModule.createRealm();3realm.global.a = 1;4console.log(realm.global.a);5var vm = require('vm');6var createRealm = function() {7 return vm.createContext();8};9exports.createRealm = createRealm;

Full Screen

Using AI Code Generation

copy

Full Screen

1var realm = new wpt.createRealm();2realm.eval("var x = 10;");3var result = realm.eval("x");4var result = realm.eval("y");5var realm = new wpt.createRealm();6realm.eval("var x = 10;");7var result = realm.eval("x");8var result = realm.eval("y");9var realm = new wpt.createRealm();10realm.eval("var x = 10;");11var result = realm.eval("x");12var result = realm.eval("y");13var realm = new wpt.createRealm();14realm.eval("var x = 10;");15var result = realm.eval("x");16var result = realm.eval("y");17var realm = new wpt.createRealm();18realm.eval("var x = 10;");19var result = realm.eval("x");20var result = realm.eval("y");21var realm = new wpt.createRealm();22realm.eval("var x = 10;");23var result = realm.eval("x");24var result = realm.eval("y");25var realm = new wpt.createRealm();26realm.eval("var x = 10;");27var result = realm.eval("x");28var result = realm.eval("y");29var realm = new wpt.createRealm();30realm.eval("var x = 10;");31var result = realm.eval("x");

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful