123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- import { expect } from "chai";
- import {
- AddAuthority,
- RemoveAuthority,
- ApplySystem,
- ApproveSystem,
- RemoveSystem,
- } from "../../../clients/bolt-sdk/lib";
- export function world(framework) {
- describe("World authority", () => {
- it("Add authority", async () => {
- const addAuthority = await AddAuthority({
- authority: framework.provider.wallet.publicKey,
- newAuthority: framework.provider.wallet.publicKey,
- world: framework.worldPda,
- connection: framework.provider.connection,
- });
- await framework.provider.sendAndConfirm(addAuthority.transaction, [], {
- skipPreflight: true,
- });
- const worldAccount = await framework.worldProgram.account.world.fetch(
- framework.worldPda,
- );
- expect(
- worldAccount.authorities.some((auth) =>
- auth.equals(framework.provider.wallet.publicKey),
- ),
- );
- });
- it("Add a second authority", async () => {
- const addAuthority = await AddAuthority({
- authority: framework.provider.wallet.publicKey,
- newAuthority: framework.secondAuthority,
- world: framework.worldPda,
- connection: framework.provider.connection,
- });
- await framework.provider.sendAndConfirm(addAuthority.transaction);
- const worldAccount = await framework.worldProgram.account.world.fetch(
- framework.worldPda,
- );
- expect(
- worldAccount.authorities.some((auth) =>
- auth.equals(framework.secondAuthority),
- ),
- );
- });
- it("Remove an authority", async () => {
- const removeAuthority = await RemoveAuthority({
- authority: framework.provider.wallet.publicKey,
- authorityToDelete: framework.secondAuthority,
- world: framework.worldPda,
- connection: framework.provider.connection,
- });
- await framework.provider.sendAndConfirm(removeAuthority.transaction);
- const worldAccount = await framework.worldProgram.account.world.fetch(
- framework.worldPda,
- );
- expect(
- !worldAccount.authorities.some((auth) =>
- auth.equals(framework.secondAuthority),
- ),
- );
- });
- it("Whitelist Fly System", async () => {
- const approveSystem = await ApproveSystem({
- authority: framework.provider.wallet.publicKey,
- systemToApprove: framework.systemFly.programId,
- world: framework.worldPda,
- });
- await framework.provider.sendAndConfirm(approveSystem.transaction, [], {
- skipPreflight: true,
- });
- // Get World and check permissionless and systems
- const worldAccount = await framework.worldProgram.account.world.fetch(
- framework.worldPda,
- );
- expect(worldAccount.permissionless).to.equal(false);
- expect(worldAccount.systems.length).to.be.greaterThan(0);
- });
- it("Whitelist Apply Velocity System system", async () => {
- const approveSystem = await ApproveSystem({
- authority: framework.provider.wallet.publicKey,
- systemToApprove: framework.systemApplyVelocity.programId,
- world: framework.worldPda,
- });
- await framework.provider.sendAndConfirm(approveSystem.transaction, [], {
- skipPreflight: true,
- });
- // Get World and check permissionless and systems
- const worldAccount = await framework.worldProgram.account.world.fetch(
- framework.worldPda,
- );
- expect(worldAccount.permissionless).to.equal(false);
- expect(worldAccount.systems.length).to.be.greaterThan(0);
- });
- it("Apply Fly System on Entity 1", async () => {
- const applySystem = await ApplySystem({
- authority: framework.provider.wallet.publicKey,
- systemId: framework.systemFly.programId,
- world: framework.worldPda,
- entities: [
- {
- entity: framework.entity1Pda,
- components: [
- { componentId: framework.exampleComponentPosition.programId },
- ],
- },
- ],
- });
- await framework.provider.sendAndConfirm(applySystem.transaction);
- });
- it("Remove Fly System", async () => {
- const removeSystem = await RemoveSystem({
- authority: framework.provider.wallet.publicKey,
- systemToRemove: framework.systemFly.programId,
- world: framework.worldPda,
- });
- await framework.provider.sendAndConfirm(removeSystem.transaction, [], {
- skipPreflight: true,
- });
- // Get World and check permissionless and systems
- const worldAccount = await framework.worldProgram.account.world.fetch(
- framework.worldPda,
- );
- expect(worldAccount.permissionless).to.equal(false);
- expect(worldAccount.systems.length).to.be.greaterThan(0);
- });
- it("Apply unauthorized Fly System on Entity 1", async () => {
- const applySystem = await ApplySystem({
- authority: framework.provider.wallet.publicKey,
- systemId: framework.systemFly.programId,
- world: framework.worldPda,
- entities: [
- {
- entity: framework.entity1Pda,
- components: [
- { componentId: framework.exampleComponentPosition.programId },
- ],
- },
- ],
- });
- let invalid = false;
- try {
- await framework.provider.sendAndConfirm(applySystem.transaction);
- } catch (error) {
- expect(error.logs.join(" ")).to.contain(
- "Error Code: SystemNotApproved",
- );
- invalid = true;
- }
- expect(invalid).to.equal(true);
- });
- });
- }
|