Skip to content

Commit fd5d415

Browse files
committed
♻️ Authority & Session checks
1 parent 39f2318 commit fd5d415

File tree

22 files changed

+157
-113
lines changed

22 files changed

+157
-113
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ which = "^7"
6262
tokio = { version = "^1", features = ["full"] }
6363
sysinfo = "^0"
6464
bytemuck_derive = "^1"
65+
sha2 = { version = "^0.10" }
6566

6667
[profile.release]
6768
overflow-checks = true

clients/typescript/src/generated/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import gpl_session from "./idl/gpl_session.json";
1111
export * from "./accounts";
1212
export * from "./errors";
1313
export * from "./instructions";
14-
export * from "./types";
14+
// Re-export the IDL type under a distinct name to avoid name collisions with account types
15+
export type { World as WorldIdl } from "./types";
1516

1617
/**
1718
* Program address

clients/typescript/src/world/transactions.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
Transaction,
2828
type TransactionInstruction,
2929
} from "@solana/web3.js";
30-
import type WorldProgram from "../generated";
30+
import type { World as WorldProgram } from "../generated/types/world";
3131
import {
3232
createInitializeRegistryInstruction,
3333
PROGRAM_ID,
@@ -155,9 +155,7 @@ export async function AddAuthority({
155155
instruction: TransactionInstruction;
156156
transaction: Transaction;
157157
}> {
158-
const program = new Program(
159-
worldIdl as Idl,
160-
) as unknown as Program<WorldProgram>;
158+
const program = new Program(worldIdl as Idl) as unknown as Program;
161159
const worldInstance = await World.fromAccountAddress(connection, world);
162160
const worldId = new BN(worldInstance.id);
163161
const instruction = await program.methods
@@ -197,9 +195,7 @@ export async function RemoveAuthority({
197195
instruction: TransactionInstruction;
198196
transaction: Transaction;
199197
}> {
200-
const program = new Program(
201-
worldIdl as Idl,
202-
) as unknown as Program<WorldProgram>;
198+
const program = new Program(worldIdl as Idl) as unknown as Program;
203199
const worldInstance = await World.fromAccountAddress(connection, world);
204200
const worldId = new BN(worldInstance.id);
205201
const instruction = await program.methods
@@ -236,9 +232,7 @@ export async function ApproveSystem({
236232
instruction: TransactionInstruction;
237233
transaction: Transaction;
238234
}> {
239-
const program = new Program(
240-
worldIdl as Idl,
241-
) as unknown as Program<WorldProgram>;
235+
const program = new Program(worldIdl as Idl) as unknown as Program;
242236
const instruction = await program.methods
243237
.approveSystem()
244238
.accounts({
@@ -273,9 +267,7 @@ export async function RemoveSystem({
273267
instruction: TransactionInstruction;
274268
transaction: Transaction;
275269
}> {
276-
const program = new Program(
277-
worldIdl as Idl,
278-
) as unknown as Program<WorldProgram>;
270+
const program = new Program(worldIdl as Idl) as unknown as Program;
279271
const instruction = await program.methods
280272
.removeSystem()
281273
.accounts({
@@ -359,9 +351,7 @@ export async function DestroyComponent({
359351
instruction: TransactionInstruction;
360352
transaction: Transaction;
361353
}> {
362-
const program = new Program(
363-
worldIdl as Idl,
364-
) as unknown as Program<WorldProgram>;
354+
const program = new Program(worldIdl as Idl) as unknown as Program;
365355
const componentProgramData = FindComponentProgramDataPda({
366356
programId: componentId,
367357
});
@@ -450,9 +440,7 @@ async function createApplySystemInstruction({
450440
extraAccounts,
451441
args,
452442
}: ApplySystemInstruction): Promise<web3.TransactionInstruction> {
453-
const program = new Program(
454-
worldIdl as Idl,
455-
) as unknown as Program<WorldProgram>;
443+
const program = new Program(worldIdl as Idl) as unknown as Program;
456444
let componentCount = 0;
457445
entities.forEach(function (entity) {
458446
componentCount += entity.components.length;

clients/typescript/test/framework.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { type Velocity } from "../../../target/types/velocity";
1212
import { type SystemSimpleMovement } from "../../../target/types/system_simple_movement";
1313
import { type SystemFly } from "../../../target/types/system_fly";
1414
import { type SystemApplyVelocity } from "../../../target/types/system_apply_velocity";
15-
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
15+
import { Connection, Keypair, PublicKey, Transaction } from "@solana/web3.js";
1616

1717
export class Framework {
1818
provider: anchor.AnchorProvider;
@@ -57,4 +57,8 @@ export class Framework {
5757
anchor.Wallet.local(),
5858
);
5959
}
60+
61+
async sendAndConfirm(transaction: Transaction) {
62+
return this.provider.sendAndConfirm(transaction);
63+
}
6064
}

clients/typescript/test/low-level/ecs.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,6 @@ export function ecs(framework) {
222222
expect(position.z.toNumber()).to.equal(0);
223223
});
224224

225-
// FIXME: Remove this.
226-
return;
227-
228225
it("Apply Simple Movement System (Right) on Entity 1", async () => {
229226
const instruction = await framework.worldProgram.methods
230227
.apply(SerializeArgs({ direction: Direction.Right }))

clients/typescript/test/low-level/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ describe("Low level API", () => {
88
const framework: Framework = new Framework();
99
world(framework);
1010
ecs(framework);
11-
// session(framework);
12-
// permissioning(framework);
11+
session(framework);
12+
permissioning(framework);
1313
});

clients/typescript/test/low-level/permissioning/component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
FindComponentPda,
66
SerializeArgs,
77
CPI_AUTH_ADDRESS,
8+
FindBufferPda,
89
} from "../../../lib";
910
import { assert, expect } from "chai";
1011

@@ -65,6 +66,7 @@ export function component(framework) {
6566
const instruction = await framework.worldProgram.methods
6667
.apply(SerializeArgs())
6768
.accounts({
69+
buffer: FindBufferPda(),
6870
authority: keypair.publicKey,
6971
boltSystem: framework.systemFly.programId,
7072
world: framework.worldPda,
@@ -115,6 +117,7 @@ export function component(framework) {
115117
const instruction = await framework.worldProgram.methods
116118
.apply(SerializeArgs())
117119
.accounts({
120+
buffer: FindBufferPda(),
118121
authority: framework.provider.wallet.publicKey,
119122
boltSystem: framework.systemFly.programId,
120123
world: framework.worldPda,

clients/typescript/test/low-level/permissioning/world.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { expect } from "chai";
2-
import { anchor, CPI_AUTH_ADDRESS, SerializeArgs } from "../../../lib";
2+
import {
3+
anchor,
4+
CPI_AUTH_ADDRESS,
5+
FindBufferPda,
6+
SerializeArgs,
7+
} from "../../../lib";
38

49
export function world(framework) {
510
describe("World authority", () => {
@@ -118,6 +123,7 @@ export function world(framework) {
118123
const instruction = await framework.worldProgram.methods
119124
.apply(SerializeArgs())
120125
.accounts({
126+
buffer: FindBufferPda(),
121127
authority: framework.provider.wallet.publicKey,
122128
boltSystem: framework.systemFly.programId,
123129
world: framework.worldPda,
@@ -166,6 +172,7 @@ export function world(framework) {
166172
const instruction = await framework.worldProgram.methods
167173
.apply(SerializeArgs())
168174
.accounts({
175+
buffer: FindBufferPda(),
169176
authority: framework.provider.wallet.publicKey,
170177
boltSystem: framework.systemFly.programId,
171178
world: framework.worldPda,

clients/typescript/test/low-level/session.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
FindSessionTokenPda,
99
BN,
1010
CPI_AUTH_ADDRESS,
11+
FindBufferPda,
1112
} from "../../lib";
1213
import { Keypair } from "@solana/web3.js";
1314

@@ -90,6 +91,7 @@ export function session(framework) {
9091
const instruction = await framework.worldProgram.methods
9192
.applyWithSession(SerializeArgs())
9293
.accounts({
94+
buffer: FindBufferPda(),
9395
authority: sessionSigner.publicKey,
9496
boltSystem: framework.systemFly.programId,
9597
world: framework.worldPda,
@@ -179,6 +181,7 @@ export function session(framework) {
179181
const instruction = await framework.worldProgram.methods
180182
.applyWithSession(SerializeArgs())
181183
.accounts({
184+
buffer: FindBufferPda(),
182185
authority: sessionSigner.publicKey,
183186
boltSystem: framework.systemFly.programId,
184187
world: framework.worldPda,

0 commit comments

Comments
 (0)