basic-3.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. const assert = require("assert");
  2. const anchor = require("@project-serum/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.initialize().
  14. accounts({
  15. puppet: newPuppetAccount.publicKey,
  16. user: provider.wallet.publicKey,
  17. systemProgram: SystemProgram.programId,
  18. }).
  19. signers([newPuppetAccount]).rpc();
  20. // Invoke the puppet master to perform a CPI to the puppet.
  21. await puppetMaster.methods.pullStrings(new anchor.BN(111)).
  22. accounts({
  23. puppet: newPuppetAccount.publicKey,
  24. puppetProgram: puppet.programId,
  25. }).rpc();
  26. // Check the state updated.
  27. puppetAccount = await puppet.account.data.fetch(newPuppetAccount.publicKey);
  28. assert.ok(puppetAccount.data.eq(new anchor.BN(111)));
  29. });
  30. });