basic-3.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const assert = require("assert");
  2. const anchor = require("@coral-xyz/anchor");
  3. const { SystemProgram } = anchor.web3;
  4. describe("basic-3", () => {
  5. const provider = anchor.AnchorProvider.local();
  6. // Configure the client to use the local cluster.
  7. anchor.setProvider(provider);
  8. it("Performs CPI from puppet master to puppet", async () => {
  9. const puppetMaster = anchor.workspace.PuppetMaster;
  10. const puppet = anchor.workspace.Puppet;
  11. // Initialize a new puppet account.
  12. const newPuppetAccount = anchor.web3.Keypair.generate();
  13. const tx = await puppet.methods
  14. .initialize()
  15. .accounts({
  16. puppet: newPuppetAccount.publicKey,
  17. user: provider.wallet.publicKey,
  18. systemProgram: SystemProgram.programId,
  19. })
  20. .signers([newPuppetAccount])
  21. .rpc();
  22. // Invoke the puppet master to perform a CPI to the puppet.
  23. await puppetMaster.methods
  24. .pullStrings(new anchor.BN(111))
  25. .accounts({
  26. puppet: newPuppetAccount.publicKey,
  27. puppetProgram: puppet.programId,
  28. })
  29. .rpc();
  30. // Check the state updated.
  31. puppetAccount = await puppet.account.data.fetch(newPuppetAccount.publicKey);
  32. assert.ok(puppetAccount.data.eq(new anchor.BN(111)));
  33. });
  34. });