world.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {
  2. anchor,
  3. FindRegistryPda,
  4. FindWorldPda,
  5. BN,
  6. } from "../../clients/bolt-sdk/lib";
  7. export function world(framework) {
  8. describe("World", () => {
  9. it("Initialize registry", async () => {
  10. const registryPda = FindRegistryPda({});
  11. const instruction = await framework.worldProgram.methods
  12. .initializeRegistry()
  13. .accounts({
  14. registry: registryPda,
  15. payer: framework.provider.wallet.publicKey,
  16. })
  17. .instruction();
  18. const transaction = new anchor.web3.Transaction().add(instruction);
  19. await framework.provider.sendAndConfirm(transaction);
  20. });
  21. it("Initialize world", async () => {
  22. const registryPda = FindRegistryPda({});
  23. const registry =
  24. await framework.worldProgram.account.registry.fetch(registryPda);
  25. framework.worldId = new BN(registry.worlds);
  26. framework.worldPda = FindWorldPda({ worldId: framework.worldId });
  27. const instruction = await framework.worldProgram.methods
  28. .initializeNewWorld()
  29. .accounts({
  30. payer: framework.provider.wallet.publicKey,
  31. world: framework.worldPda,
  32. registry: registryPda,
  33. })
  34. .instruction();
  35. const transaction = new anchor.web3.Transaction().add(instruction);
  36. await framework.provider.sendAndConfirm(transaction);
  37. });
  38. it("Initialize second world", async () => {
  39. const registryPda = FindRegistryPda({});
  40. const registry =
  41. await framework.worldProgram.account.registry.fetch(registryPda);
  42. const worldId = new BN(registry.worlds);
  43. const worldPda = FindWorldPda({ worldId });
  44. const instruction = await framework.worldProgram.methods
  45. .initializeNewWorld()
  46. .accounts({
  47. payer: framework.provider.wallet.publicKey,
  48. world: worldPda,
  49. registry: registryPda,
  50. })
  51. .instruction();
  52. const transaction = new anchor.web3.Transaction().add(instruction);
  53. await framework.provider.sendAndConfirm(transaction);
  54. });
  55. });
  56. }