@@ -10,6 +10,12 @@ import { SystemApplyVelocity } from "../target/types/system_apply_velocity";
10
10
import { World } from "../target/types/world" ;
11
11
import { expect } from "chai" ;
12
12
import BN from "bn.js" ;
13
+ import {
14
+ FindComponentPda ,
15
+ FindEntityPda ,
16
+ FindWorldPda ,
17
+ FindWorldRegistryPda ,
18
+ } from "../clients/bolt-sdk" ;
13
19
14
20
enum Direction {
15
21
Left = "Left" ,
@@ -57,7 +63,7 @@ describe("bolt", () => {
57
63
let componentVelocityEntity1 : PublicKey ;
58
64
59
65
it ( "InitializeWorldsRegistry" , async ( ) => {
60
- const registryPda = FindWorldRegistryPda ( worldProgram ) ;
66
+ const registryPda = FindWorldRegistryPda ( worldProgram . programId ) ;
61
67
await worldProgram . methods
62
68
. initializeRegistry ( )
63
69
. accounts ( {
@@ -68,9 +74,9 @@ describe("bolt", () => {
68
74
} ) ;
69
75
70
76
it ( "InitializeNewWorld" , async ( ) => {
71
- const registryPda = FindWorldRegistryPda ( worldProgram ) ;
77
+ const registryPda = FindWorldRegistryPda ( worldProgram . programId ) ;
72
78
73
- const worldPda = FindWorldPda ( worldProgram , new BN ( 0 ) ) ;
79
+ const worldPda = FindWorldPda ( new BN ( 0 ) , worldProgram . programId ) ;
74
80
await worldProgram . methods
75
81
. initializeNewWorld ( )
76
82
. accounts ( {
@@ -82,9 +88,9 @@ describe("bolt", () => {
82
88
} ) ;
83
89
84
90
it ( "InitializeNewWorld 2" , async ( ) => {
85
- const registryPda = FindWorldRegistryPda ( worldProgram ) ;
91
+ const registryPda = FindWorldRegistryPda ( worldProgram . programId ) ;
86
92
87
- const worldPda = FindWorldPda ( worldProgram , new BN ( 1 ) ) ;
93
+ const worldPda = FindWorldPda ( new BN ( 1 ) , worldProgram . programId ) ;
88
94
await worldProgram . methods
89
95
. initializeNewWorld ( )
90
96
. accounts ( {
@@ -96,8 +102,8 @@ describe("bolt", () => {
96
102
} ) ;
97
103
98
104
it ( "Add entity 1" , async ( ) => {
99
- const worldPda = FindWorldPda ( worldProgram , new BN ( 0 ) ) ;
100
- entity1 = FindEntityPda ( worldProgram , new BN ( 0 ) , new BN ( 0 ) ) ;
105
+ const worldPda = FindWorldPda ( new BN ( 0 ) , worldProgram . programId ) ;
106
+ entity1 = FindEntityPda ( new BN ( 0 ) , new BN ( 0 ) , null , worldProgram . programId ) ;
101
107
await worldProgram . methods
102
108
. addEntity ( null )
103
109
. accounts ( {
@@ -109,9 +115,9 @@ describe("bolt", () => {
109
115
} ) ;
110
116
111
117
it ( "Add entity 2" , async ( ) => {
112
- const worldPda = FindWorldPda ( worldProgram , new BN ( 0 ) ) ;
118
+ const worldPda = FindWorldPda ( new BN ( 0 ) , worldProgram . programId ) ;
113
119
114
- entity2 = FindEntityPda ( worldProgram , new BN ( 0 ) , new BN ( 1 ) ) ;
120
+ entity2 = FindEntityPda ( new BN ( 0 ) , new BN ( 1 ) , null , worldProgram . programId ) ;
115
121
await worldProgram . methods
116
122
. addEntity ( null )
117
123
. accounts ( {
@@ -123,9 +129,14 @@ describe("bolt", () => {
123
129
} ) ;
124
130
125
131
it ( "Add entity 3" , async ( ) => {
126
- const worldPda = FindWorldPda ( worldProgram , new BN ( 0 ) ) ;
132
+ const worldPda = FindWorldPda ( new BN ( 0 ) , worldProgram . programId ) ;
127
133
128
- const entityPda = FindEntityPda ( worldProgram , new BN ( 0 ) , new BN ( 2 ) ) ;
134
+ const entityPda = FindEntityPda (
135
+ new BN ( 0 ) ,
136
+ new BN ( 2 ) ,
137
+ null ,
138
+ worldProgram . programId
139
+ ) ;
129
140
await worldProgram . methods
130
141
. addEntity ( null )
131
142
. accounts ( {
@@ -137,9 +148,14 @@ describe("bolt", () => {
137
148
} ) ;
138
149
139
150
it ( "Add entity 4 with extra seeds" , async ( ) => {
140
- const worldPda = FindWorldPda ( worldProgram , new BN ( 0 ) ) ;
151
+ const worldPda = FindWorldPda ( new BN ( 0 ) , worldProgram . programId ) ;
141
152
const seed = "extra-seed" ;
142
- let entity3 = FindEntityPda ( worldProgram , new BN ( 0 ) , new BN ( 3 ) , seed ) ;
153
+ let entity3 = FindEntityPda (
154
+ new BN ( 0 ) ,
155
+ new BN ( 3 ) ,
156
+ seed ,
157
+ worldProgram . programId
158
+ ) ;
143
159
144
160
await worldProgram . methods
145
161
. addEntity ( seed )
@@ -188,8 +204,7 @@ describe("bolt", () => {
188
204
it ( "Initialize Position Component on Entity 1" , async ( ) => {
189
205
componentPositionEntity1 = FindComponentPda (
190
206
boltComponentPositionProgram . programId ,
191
- entity1 ,
192
- ""
207
+ entity1
193
208
) ;
194
209
195
210
console . log ( "Component Position E1: " , componentPositionEntity1 . toBase58 ( ) ) ;
@@ -464,47 +479,4 @@ describe("bolt", () => {
464
479
console . log ( "| |" ) ;
465
480
console . log ( "+-----------------------------+" ) ;
466
481
} ) ;
467
-
468
- // Utils
469
-
470
- function FindWorldRegistryPda ( program : Program < World > ) {
471
- return PublicKey . findProgramAddressSync (
472
- [ Buffer . from ( "registry" ) ] ,
473
- program . programId
474
- ) [ 0 ] ;
475
- }
476
-
477
- function FindWorldPda ( program : Program < World > , id : BN ) {
478
- return PublicKey . findProgramAddressSync (
479
- [ Buffer . from ( "world" ) , id . toBuffer ( "be" , 8 ) ] ,
480
- program . programId
481
- ) [ 0 ] ;
482
- }
483
-
484
- function FindEntityPda (
485
- program : Program < World > ,
486
- worldId : BN ,
487
- entityId : BN ,
488
- extraSeed ?: string
489
- ) {
490
- let seeds = [ Buffer . from ( "entity" ) , worldId . toBuffer ( "be" , 8 ) ] ;
491
- if ( extraSeed ) {
492
- seeds . push ( Buffer . from ( new Uint8Array ( 8 ) ) ) ;
493
- seeds . push ( Buffer . from ( extraSeed ) ) ;
494
- } else {
495
- seeds . push ( entityId . toBuffer ( "be" , 8 ) ) ;
496
- }
497
- return PublicKey . findProgramAddressSync ( seeds , program . programId ) [ 0 ] ;
498
- }
499
-
500
- function FindComponentPda (
501
- program : PublicKey ,
502
- entity : PublicKey ,
503
- seed : string = "component"
504
- ) {
505
- return PublicKey . findProgramAddressSync (
506
- [ Buffer . from ( seed ) , entity . toBytes ( ) ] ,
507
- program
508
- ) [ 0 ] ;
509
- }
510
482
} ) ;
0 commit comments