123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- import { expect } from "chai";
- import { anchor, SerializeArgs } from "../../../clients/bolt-sdk/lib";
- export function world(framework) {
- describe("World authority", () => {
- it("Add authority", async () => {
- const instruction = await framework.worldProgram.methods
- .addAuthority(framework.worldId)
- .accounts({
- authority: framework.provider.wallet.publicKey,
- newAuthority: framework.provider.wallet.publicKey,
- world: framework.worldPda,
- })
- .instruction();
- const transaction = new anchor.web3.Transaction().add(instruction);
- await framework.provider.sendAndConfirm(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 instruction = await framework.worldProgram.methods
- .addAuthority(framework.worldId)
- .accounts({
- authority: framework.provider.wallet.publicKey,
- newAuthority: framework.secondAuthority,
- world: framework.worldPda,
- })
- .instruction();
- const transaction = new anchor.web3.Transaction().add(instruction);
- await framework.provider.sendAndConfirm(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 instruction = await framework.worldProgram.methods
- .removeAuthority(framework.worldId)
- .accounts({
- authority: framework.provider.wallet.publicKey,
- authorityToDelete: framework.secondAuthority,
- world: framework.worldPda,
- })
- .instruction();
- const transaction = new anchor.web3.Transaction().add(instruction);
- await framework.provider.sendAndConfirm(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 instruction = await framework.worldProgram.methods
- .approveSystem()
- .accounts({
- authority: framework.provider.wallet.publicKey,
- system: framework.systemFly.programId,
- world: framework.worldPda,
- })
- .instruction();
- const transaction = new anchor.web3.Transaction().add(instruction);
- await framework.provider.sendAndConfirm(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 instruction = await framework.worldProgram.methods
- .approveSystem()
- .accounts({
- authority: framework.provider.wallet.publicKey,
- system: framework.systemApplyVelocity.programId,
- world: framework.worldPda,
- })
- .instruction();
- const transaction = new anchor.web3.Transaction().add(instruction);
- await framework.provider.sendAndConfirm(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 instruction = await framework.worldProgram.methods
- .apply(SerializeArgs())
- .accounts({
- authority: framework.provider.wallet.publicKey,
- boltSystem: framework.systemFly.programId,
- world: framework.worldPda,
- })
- .remainingAccounts([
- {
- pubkey: framework.exampleComponentPosition.programId,
- isSigner: false,
- isWritable: false,
- },
- {
- pubkey: framework.componentPositionEntity1Pda,
- isSigner: false,
- isWritable: true,
- },
- ])
- .instruction();
- const transaction = new anchor.web3.Transaction().add(instruction);
- await framework.provider.sendAndConfirm(transaction);
- });
- it("Remove Fly System", async () => {
- const instruction = await framework.worldProgram.methods
- .removeSystem()
- .accounts({
- authority: framework.provider.wallet.publicKey,
- system: framework.systemFly.programId,
- world: framework.worldPda,
- })
- .instruction();
- const transaction = new anchor.web3.Transaction().add(instruction);
- await framework.provider.sendAndConfirm(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 instruction = await framework.worldProgram.methods
- .apply(SerializeArgs())
- .accounts({
- authority: framework.provider.wallet.publicKey,
- boltSystem: framework.systemFly.programId,
- world: framework.worldPda,
- })
- .remainingAccounts([
- {
- pubkey: framework.exampleComponentPosition.programId,
- isSigner: false,
- isWritable: false,
- },
- {
- pubkey: framework.componentPositionEntity1Pda,
- isSigner: false,
- isWritable: true,
- },
- ])
- .instruction();
- const transaction = new anchor.web3.Transaction().add(instruction);
- let invalid = false;
- try {
- await framework.provider.sendAndConfirm(transaction);
- } catch (error) {
- expect(error.logs.join(" ")).to.contain(
- "Error Code: SystemNotApproved",
- );
- invalid = true;
- }
- expect(invalid).to.equal(true);
- });
- it("Check invalid component init without CPI", async () => {
- let invalid = false;
- try {
- await framework.exampleComponentPosition.methods
- .initialize()
- .accounts({
- payer: framework.provider.wallet.publicKey,
- data: framework.componentPositionEntity1Pda,
- entity: framework.entity1Pda,
- authority: framework.provider.wallet.publicKey,
- })
- .rpc();
- } catch (error) {
- expect(error.message).to.contain("Error Code: InvalidCaller");
- invalid = true;
- }
- expect(invalid).to.equal(true);
- });
- it("Check invalid component update without CPI", async () => {
- let invalid = false;
- try {
- await framework.exampleComponentPosition.methods
- .update(Buffer.from(""))
- .accounts({
- boltComponent: framework.componentPositionEntity4Pda,
- authority: framework.provider.wallet.publicKey,
- })
- .rpc();
- } catch (error) {
- expect(error.message).to.contain("Error Code: InvalidCaller");
- invalid = true;
- }
- expect(invalid).to.equal(true);
- });
- });
- }
|