basic-3.js 1.2 KB

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