basic-3.js 1.2 KB

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