bolt.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { type Program, web3 } from "@coral-xyz/anchor";
  3. import { type PublicKey } from "@solana/web3.js";
  4. import { type Position } from "../target/types/position";
  5. import { type Velocity } from "../target/types/velocity";
  6. import { type BoltComponent } from "../target/types/bolt_component";
  7. import { type SystemSimpleMovement } from "../target/types/system_simple_movement";
  8. import { type SystemFly } from "../target/types/system_fly";
  9. import { type SystemApplyVelocity } from "../target/types/system_apply_velocity";
  10. import { type World } from "../target/types/world";
  11. import { expect } from "chai";
  12. import BN from "bn.js";
  13. import {
  14. createDelegateInstruction,
  15. createInitializeRegistryInstruction,
  16. DELEGATION_PROGRAM_ID,
  17. FindComponentPda,
  18. FindEntityPda,
  19. FindWorldPda,
  20. FindWorldRegistryPda,
  21. SYSVAR_INSTRUCTIONS_PUBKEY,
  22. } from "../clients/bolt-sdk";
  23. import { createUndelegateInstruction } from "../clients/bolt-sdk/lib/delegation/undelegate";
  24. enum Direction {
  25. Left = "Left",
  26. Right = "Right",
  27. Up = "Up",
  28. Down = "Down",
  29. }
  30. function serializeArgs(args: any = {}) {
  31. const jsonString = JSON.stringify(args);
  32. const encoder = new TextEncoder();
  33. const binaryData = encoder.encode(jsonString);
  34. return Buffer.from(
  35. binaryData.buffer,
  36. binaryData.byteOffset,
  37. binaryData.byteLength
  38. );
  39. }
  40. describe("bolt", () => {
  41. const provider = anchor.AnchorProvider.env();
  42. anchor.setProvider(provider);
  43. const worldProgram = anchor.workspace.World as Program<World>;
  44. const boltComponentPositionProgram = anchor.workspace
  45. .Position as Program<Position>;
  46. const boltComponentVelocityProgram = anchor.workspace
  47. .Velocity as Program<Velocity>;
  48. const boltComponentProgramOrigin = anchor.workspace
  49. .BoltComponent as Program<BoltComponent>;
  50. const systemSimpleMovement = (
  51. anchor.workspace.SystemSimpleMovement as Program<SystemSimpleMovement>
  52. ).programId;
  53. const systemFly = (anchor.workspace.SystemFly as Program<SystemFly>)
  54. .programId;
  55. const applyVelocity = (
  56. anchor.workspace.SystemApplyVelocity as Program<SystemApplyVelocity>
  57. ).programId;
  58. let entity1: PublicKey;
  59. let entity2: PublicKey;
  60. let entity5: PublicKey;
  61. let componentPositionEntity1: PublicKey;
  62. let componentPositionEntity2: PublicKey;
  63. let componentPositionEntity5: PublicKey;
  64. let componentVelocityEntity1: PublicKey;
  65. it("InitializeWorldsRegistry", async () => {
  66. const registryPda = FindWorldRegistryPda(worldProgram.programId);
  67. const initializeRegistryIx = createInitializeRegistryInstruction({
  68. registry: registryPda,
  69. payer: provider.wallet.publicKey,
  70. });
  71. const tx = new anchor.web3.Transaction().add(initializeRegistryIx);
  72. await provider.sendAndConfirm(tx);
  73. });
  74. it("InitializeNewWorld", async () => {
  75. const registryPda = FindWorldRegistryPda(worldProgram.programId);
  76. const worldPda = FindWorldPda(new BN(0), worldProgram.programId);
  77. const res = await worldProgram.methods
  78. .initializeNewWorld()
  79. .accounts({
  80. world: worldPda,
  81. registry: registryPda,
  82. payer: provider.wallet.publicKey,
  83. })
  84. .rpc();
  85. console.log(res);
  86. });
  87. it("InitializeNewWorld 2", async () => {
  88. const registryPda = FindWorldRegistryPda(worldProgram.programId);
  89. const worldPda = FindWorldPda(new BN(1), worldProgram.programId);
  90. await worldProgram.methods
  91. .initializeNewWorld()
  92. .accounts({
  93. world: worldPda,
  94. registry: registryPda,
  95. payer: provider.wallet.publicKey,
  96. })
  97. .rpc();
  98. });
  99. it("Add entity 1", async () => {
  100. const worldPda = FindWorldPda(new BN(0), worldProgram.programId);
  101. entity1 = FindEntityPda(new BN(0), new BN(0), null, worldProgram.programId);
  102. await worldProgram.methods
  103. .addEntity(null)
  104. .accounts({
  105. world: worldPda,
  106. entity: entity1,
  107. payer: provider.wallet.publicKey,
  108. })
  109. .rpc();
  110. });
  111. it("Add entity 2", async () => {
  112. const worldPda = FindWorldPda(new BN(0), worldProgram.programId);
  113. entity2 = FindEntityPda(new BN(0), new BN(1), null, worldProgram.programId);
  114. await worldProgram.methods
  115. .addEntity(null)
  116. .accounts({
  117. world: worldPda,
  118. entity: entity2,
  119. payer: provider.wallet.publicKey,
  120. })
  121. .rpc();
  122. });
  123. it("Add entity 3", async () => {
  124. const worldPda = FindWorldPda(new BN(0), worldProgram.programId);
  125. const entityPda = FindEntityPda(
  126. new BN(0),
  127. new BN(2),
  128. null,
  129. worldProgram.programId
  130. );
  131. await worldProgram.methods
  132. .addEntity(null)
  133. .accounts({
  134. world: worldPda,
  135. entity: entityPda,
  136. payer: provider.wallet.publicKey,
  137. })
  138. .rpc();
  139. });
  140. it("Add entity 4 with extra seeds", async () => {
  141. const worldPda = FindWorldPda(new BN(0), worldProgram.programId);
  142. const seed = "extra-seed";
  143. const entity4 = FindEntityPda(
  144. new BN(0),
  145. new BN(3),
  146. seed,
  147. worldProgram.programId
  148. );
  149. await worldProgram.methods
  150. .addEntity(seed)
  151. .accounts({
  152. world: worldPda,
  153. entity: entity4,
  154. payer: provider.wallet.publicKey,
  155. })
  156. .rpc();
  157. });
  158. it("Add entity 5", async () => {
  159. const worldPda = FindWorldPda(new BN(0), worldProgram.programId);
  160. entity5 = FindEntityPda(new BN(0), new BN(4), null, worldProgram.programId);
  161. await worldProgram.methods
  162. .addEntity(null)
  163. .accounts({
  164. world: worldPda,
  165. entity: entity5,
  166. payer: provider.wallet.publicKey,
  167. })
  168. .rpc();
  169. });
  170. it("Initialize Original Component on Entity 1, trough the world instance", async () => {
  171. const componentEntity1 = FindComponentPda(
  172. boltComponentProgramOrigin.programId,
  173. entity1,
  174. "origin-component"
  175. );
  176. await worldProgram.methods
  177. .initializeComponent()
  178. .accounts({
  179. payer: provider.wallet.publicKey,
  180. data: componentEntity1,
  181. componentProgram: boltComponentProgramOrigin.programId,
  182. entity: entity1,
  183. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  184. authority: provider.wallet.publicKey,
  185. })
  186. .rpc();
  187. });
  188. it("Initialize Original Component on Entity 2, trough the world instance", async () => {
  189. const componentEntity2 = FindComponentPda(
  190. boltComponentProgramOrigin.programId,
  191. entity2,
  192. "origin-component"
  193. );
  194. await worldProgram.methods
  195. .initializeComponent()
  196. .accounts({
  197. payer: provider.wallet.publicKey,
  198. data: componentEntity2,
  199. componentProgram: boltComponentProgramOrigin.programId,
  200. entity: entity2,
  201. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  202. authority: provider.wallet.publicKey,
  203. })
  204. .rpc();
  205. });
  206. it("Initialize Position Component on Entity 1", async () => {
  207. componentPositionEntity1 = FindComponentPda(
  208. boltComponentPositionProgram.programId,
  209. entity1
  210. );
  211. await worldProgram.methods
  212. .initializeComponent()
  213. .accounts({
  214. payer: provider.wallet.publicKey,
  215. data: componentPositionEntity1,
  216. componentProgram: boltComponentPositionProgram.programId,
  217. entity: entity1,
  218. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  219. authority: worldProgram.programId,
  220. })
  221. .rpc();
  222. });
  223. it("Initialize Velocity Component on Entity 1", async () => {
  224. componentVelocityEntity1 = FindComponentPda(
  225. boltComponentVelocityProgram.programId,
  226. entity1,
  227. "component-velocity"
  228. );
  229. await worldProgram.methods
  230. .initializeComponent()
  231. .accounts({
  232. payer: provider.wallet.publicKey,
  233. data: componentVelocityEntity1,
  234. componentProgram: boltComponentVelocityProgram.programId,
  235. entity: entity1,
  236. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  237. authority: worldProgram.programId,
  238. })
  239. .rpc();
  240. });
  241. it("Initialize Position Component on Entity 2", async () => {
  242. componentPositionEntity2 = FindComponentPda(
  243. boltComponentPositionProgram.programId,
  244. entity2
  245. );
  246. await worldProgram.methods
  247. .initializeComponent()
  248. .accounts({
  249. payer: provider.wallet.publicKey,
  250. data: componentPositionEntity2,
  251. componentProgram: boltComponentPositionProgram.programId,
  252. entity: entity2,
  253. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  254. authority: worldProgram.programId,
  255. })
  256. .rpc();
  257. });
  258. it("Initialize Position Component on Entity 5", async () => {
  259. componentPositionEntity5 = FindComponentPda(
  260. boltComponentPositionProgram.programId,
  261. entity5
  262. );
  263. await worldProgram.methods
  264. .initializeComponent()
  265. .accounts({
  266. payer: provider.wallet.publicKey,
  267. data: componentPositionEntity5,
  268. componentProgram: boltComponentPositionProgram.programId,
  269. entity: entity5,
  270. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  271. authority: provider.wallet.publicKey,
  272. })
  273. .rpc();
  274. });
  275. it("Check Position on Entity 1 is default", async () => {
  276. expect(
  277. (
  278. await boltComponentPositionProgram.account.position.fetch(
  279. componentPositionEntity1
  280. )
  281. ).x.toNumber()
  282. ).to.equal(0);
  283. expect(
  284. (
  285. await boltComponentPositionProgram.account.position.fetch(
  286. componentPositionEntity1
  287. )
  288. ).y.toNumber()
  289. ).to.equal(0);
  290. expect(
  291. (
  292. await boltComponentPositionProgram.account.position.fetch(
  293. componentPositionEntity1
  294. )
  295. ).z.toNumber()
  296. ).to.equal(0);
  297. });
  298. it("Simple Movement System and Up direction on Entity 1", async () => {
  299. const args = {
  300. direction: Direction.Up,
  301. };
  302. await worldProgram.methods
  303. .apply(serializeArgs(args)) // Move Up
  304. .accounts({
  305. componentProgram: boltComponentPositionProgram.programId,
  306. boltSystem: systemSimpleMovement,
  307. boltComponent: componentPositionEntity1,
  308. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  309. authority: provider.wallet.publicKey,
  310. })
  311. .rpc();
  312. expect(
  313. (
  314. await boltComponentPositionProgram.account.position.fetch(
  315. componentPositionEntity1
  316. )
  317. ).y.toNumber()
  318. ).to.equal(1);
  319. const componentData =
  320. await boltComponentPositionProgram.account.position.fetch(
  321. componentPositionEntity1
  322. );
  323. const x = componentData.x.toNumber();
  324. const y = componentData.y.toNumber();
  325. const z = componentData.z.toNumber();
  326. console.log("+-----------------------------+");
  327. console.log("| Movement System: Entity 1 |");
  328. console.log("+----------------+------------+");
  329. console.log("| Coordinate | Value |");
  330. console.log("+----------------+------------+");
  331. console.log(`| X Position | ${String(x).padEnd(10, " ")} |`);
  332. console.log("| | |");
  333. console.log(`| Y Position | ${String(y).padEnd(10, " ")} |`);
  334. console.log("| | |");
  335. console.log(`| Z Position | ${String(z).padEnd(10, " ")} |`);
  336. console.log("+----------------+------------+");
  337. console.log("| |");
  338. console.log("+-----------------------------+");
  339. console.log("Component Position: ", componentPositionEntity1.toString());
  340. });
  341. it("Simple Movement System and Right direction on Entity 1", async () => {
  342. const args = {
  343. direction: Direction.Right,
  344. };
  345. await worldProgram.methods
  346. .apply(serializeArgs(args)) // Move Right
  347. .accounts({
  348. componentProgram: boltComponentPositionProgram.programId,
  349. boltSystem: systemSimpleMovement,
  350. boltComponent: componentPositionEntity1,
  351. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  352. authority: provider.wallet.publicKey,
  353. })
  354. .rpc();
  355. expect(
  356. (
  357. await boltComponentPositionProgram.account.position.fetch(
  358. componentPositionEntity1
  359. )
  360. ).y.toNumber()
  361. ).to.equal(1);
  362. expect(
  363. (
  364. await boltComponentPositionProgram.account.position.fetch(
  365. componentPositionEntity1
  366. )
  367. ).y.toNumber()
  368. ).to.equal(1);
  369. const componentData =
  370. await boltComponentPositionProgram.account.position.fetch(
  371. componentPositionEntity1
  372. );
  373. const x = componentData.x.toNumber();
  374. const y = componentData.y.toNumber();
  375. const z = componentData.z.toNumber();
  376. console.log("+-----------------------------+");
  377. console.log("| Movement System: Entity 1 |");
  378. console.log("+----------------+------------+");
  379. console.log("| Coordinate | Value |");
  380. console.log("+----------------+------------+");
  381. console.log(`| X Position | ${String(x).padEnd(10, " ")} |`);
  382. console.log("| | |");
  383. console.log(`| Y Position | ${String(y).padEnd(10, " ")} |`);
  384. console.log("| | |");
  385. console.log(`| Z Position | ${String(z).padEnd(10, " ")} |`);
  386. console.log("+----------------+------------+");
  387. console.log("| |");
  388. console.log("+-----------------------------+");
  389. });
  390. it("Fly System on Entity 1", async () => {
  391. await worldProgram.methods
  392. .apply(Buffer.alloc(0)) // Move Up
  393. .accounts({
  394. componentProgram: boltComponentPositionProgram.programId,
  395. boltSystem: systemFly,
  396. boltComponent: componentPositionEntity1,
  397. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  398. authority: provider.wallet.publicKey,
  399. })
  400. .rpc();
  401. expect(
  402. (
  403. await boltComponentPositionProgram.account.position.fetch(
  404. componentPositionEntity1
  405. )
  406. ).z.toNumber()
  407. ).to.equal(1);
  408. const componentData =
  409. await boltComponentPositionProgram.account.position.fetch(
  410. componentPositionEntity1
  411. );
  412. const x = componentData.x.toNumber();
  413. const y = componentData.y.toNumber();
  414. const z = componentData.z.toNumber();
  415. console.log("+-----------------------------+");
  416. console.log("| Fly: Position Entity 1 |");
  417. console.log("+----------------+------------+");
  418. console.log("| Coordinate | Value |");
  419. console.log("+----------------+------------+");
  420. console.log(`| X Position | ${String(x).padEnd(10, " ")} |`);
  421. console.log("| | |");
  422. console.log(`| Y Position | ${String(y).padEnd(10, " ")} |`);
  423. console.log("| | |");
  424. console.log(`| Z Position | ${String(z).padEnd(10, " ")} |`);
  425. console.log("+----------------+------------+");
  426. console.log("| |");
  427. console.log("+-----------------------------+");
  428. });
  429. it("Apply Velocity on Entity 1", async () => {
  430. await worldProgram.methods
  431. .apply2(Buffer.alloc(0))
  432. .accounts({
  433. componentProgram1: boltComponentVelocityProgram.programId,
  434. componentProgram2: boltComponentPositionProgram.programId,
  435. boltSystem: applyVelocity,
  436. boltComponent1: componentVelocityEntity1,
  437. boltComponent2: componentPositionEntity1,
  438. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  439. authority: provider.wallet.publicKey,
  440. })
  441. .rpc();
  442. const componentData =
  443. await boltComponentVelocityProgram.account.velocity.fetch(
  444. componentVelocityEntity1
  445. );
  446. let x = componentData.x.toNumber();
  447. let y = componentData.y.toNumber();
  448. let z = componentData.z.toNumber();
  449. const tmp = componentData.lastApplied.toNumber();
  450. console.log("+-----------------------------+");
  451. console.log("| Apply Velocity: Velocity Entity 1 |");
  452. console.log("+----------------+------------+");
  453. console.log("| Coordinate | Value |");
  454. console.log("+----------------+------------+");
  455. console.log(`| X Position | ${String(x).padEnd(10, " ")} |`);
  456. console.log("| | |");
  457. console.log(`| Y Position | ${String(y).padEnd(10, " ")} |`);
  458. console.log("| | |");
  459. console.log(`| Z Position | ${String(z).padEnd(10, " ")} |`);
  460. console.log("| | |");
  461. console.log(`| Timestamp | ${String(tmp).padEnd(10, " ")} |`);
  462. console.log("+----------------+------------+");
  463. console.log("| |");
  464. console.log("+-----------------------------+");
  465. const positionData =
  466. await boltComponentPositionProgram.account.position.fetch(
  467. componentPositionEntity1
  468. );
  469. x = positionData.x.toNumber();
  470. y = positionData.y.toNumber();
  471. z = positionData.z.toNumber();
  472. console.log("+-----------------------------+");
  473. console.log("| Apply Velocity: Position Entity 1 |");
  474. console.log("+----------------+------------+");
  475. console.log("| Coordinate | Value |");
  476. console.log("+----------------+------------+");
  477. console.log(`| X Position | ${String(x).padEnd(10, " ")} |`);
  478. console.log("| | |");
  479. console.log(`| Y Position | ${String(y).padEnd(10, " ")} |`);
  480. console.log("| | |");
  481. console.log(`| Z Position | ${String(z).padEnd(10, " ")} |`);
  482. console.log("+----------------+------------+");
  483. console.log("| |");
  484. console.log("+-----------------------------+");
  485. expect(positionData.z.toNumber()).to.not.equal(300);
  486. });
  487. it("Apply Velocity on Entity 1, with Clock external account", async () => {
  488. await worldProgram.methods
  489. .apply2(Buffer.alloc(0))
  490. .accounts({
  491. componentProgram1: boltComponentVelocityProgram.programId,
  492. componentProgram2: boltComponentPositionProgram.programId,
  493. boltSystem: applyVelocity,
  494. boltComponent1: componentVelocityEntity1,
  495. boltComponent2: componentPositionEntity1,
  496. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  497. authority: provider.wallet.publicKey,
  498. })
  499. .remainingAccounts([
  500. {
  501. pubkey: new web3.PublicKey(
  502. "SysvarC1ock11111111111111111111111111111111"
  503. ),
  504. isWritable: false,
  505. isSigner: false,
  506. },
  507. ])
  508. .rpc();
  509. const positionData =
  510. await boltComponentPositionProgram.account.position.fetch(
  511. componentPositionEntity1
  512. );
  513. // Check if the position has changed to 300 (which means the account clock was used)
  514. expect(positionData.z.toNumber()).to.equal(300);
  515. });
  516. // Check illegal authority usage
  517. it("Check invalid component update", async () => {
  518. const componentDataPrev =
  519. await boltComponentPositionProgram.account.position.fetch(
  520. componentPositionEntity5
  521. );
  522. try {
  523. await worldProgram.methods
  524. .apply(Buffer.alloc(0)) // Move Up
  525. .accounts({
  526. componentProgram: boltComponentPositionProgram.programId,
  527. boltSystem: systemFly,
  528. boltComponent: componentPositionEntity5,
  529. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  530. authority: provider.wallet.publicKey,
  531. })
  532. .rpc();
  533. } catch (e) {
  534. expect(e.message).to.contain("Invalid authority");
  535. }
  536. const componentData =
  537. await boltComponentPositionProgram.account.position.fetch(
  538. componentPositionEntity5
  539. );
  540. expect(
  541. componentDataPrev.x.toNumber() === componentData.x.toNumber() &&
  542. componentDataPrev.y.toNumber() === componentData.y.toNumber() &&
  543. componentDataPrev.z.toNumber() === componentData.z.toNumber()
  544. ).to.equal(true);
  545. });
  546. // Check illegal call, without CPI
  547. it("Check invalid init without CPI", async () => {
  548. let invalid = false;
  549. const componentVelocityEntity5 = FindComponentPda(
  550. boltComponentVelocityProgram.programId,
  551. entity5
  552. );
  553. try {
  554. await boltComponentProgramOrigin.methods
  555. .initialize()
  556. .accounts({
  557. payer: provider.wallet.publicKey,
  558. data: componentVelocityEntity5,
  559. entity: entity5,
  560. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  561. systemProgram: anchor.web3.SystemProgram.programId,
  562. authority: provider.wallet.publicKey,
  563. })
  564. .rpc();
  565. } catch (e) {
  566. invalid = true;
  567. }
  568. expect(invalid).to.equal(true);
  569. });
  570. // Check illegal call, without CPI
  571. it("Check invalid update without CPI", async () => {
  572. let invalid = false;
  573. const componentVelocityEntity5 = FindComponentPda(
  574. boltComponentVelocityProgram.programId,
  575. entity5
  576. );
  577. try {
  578. await boltComponentProgramOrigin.methods
  579. .update(null)
  580. .accounts({
  581. boltComponent: componentVelocityEntity5,
  582. instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
  583. authority: provider.wallet.publicKey,
  584. })
  585. .rpc();
  586. } catch (e) {
  587. invalid = true;
  588. }
  589. expect(invalid).to.equal(true);
  590. });
  591. // Check component delegation
  592. it("Check component delegation", async () => {
  593. const delegateIx = createDelegateInstruction({
  594. entity: entity1,
  595. account: componentPositionEntity1,
  596. ownerProgram: boltComponentPositionProgram.programId,
  597. payer: provider.wallet.publicKey,
  598. });
  599. const tx = new anchor.web3.Transaction().add(delegateIx);
  600. await provider.sendAndConfirm(tx, [], { skipPreflight: true });
  601. const acc = await provider.connection.getAccountInfo(
  602. componentPositionEntity1
  603. );
  604. expect(acc.owner.toString()).to.equal(DELEGATION_PROGRAM_ID);
  605. });
  606. // Check component undelegation
  607. it("Check component undelegation", async () => {
  608. const delegateIx = createUndelegateInstruction({
  609. payer: provider.wallet.publicKey,
  610. delegatedAccount: componentPositionEntity1,
  611. ownerProgram: boltComponentPositionProgram.programId,
  612. reimbursement: provider.wallet.publicKey,
  613. });
  614. const tx = new anchor.web3.Transaction().add(delegateIx);
  615. await provider.sendAndConfirm(tx, [], { skipPreflight: true });
  616. const acc = await provider.connection.getAccountInfo(
  617. componentPositionEntity1
  618. );
  619. expect(acc.owner).to.deep.equal(boltComponentPositionProgram.programId);
  620. });
  621. });