composite.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const assert = require("assert");
  2. const anchor = require("@project-serum/anchor");
  3. describe("composite", () => {
  4. const provider = anchor.Provider.local();
  5. // Configure the client to use the local cluster.
  6. anchor.setProvider(provider);
  7. it("Is initialized!", async () => {
  8. const program = anchor.workspace.Composite;
  9. const dummyA = new anchor.web3.Account();
  10. const dummyB = new anchor.web3.Account();
  11. const tx = await program.rpc.initialize({
  12. accounts: {
  13. dummyA: dummyA.publicKey,
  14. dummyB: dummyB.publicKey,
  15. rent: anchor.web3.SYSVAR_RENT_PUBKEY,
  16. },
  17. signers: [dummyA, dummyB],
  18. instructions: [
  19. await program.account.dummyA.createInstruction(dummyA),
  20. await program.account.dummyB.createInstruction(dummyB),
  21. ],
  22. });
  23. await program.rpc.compositeUpdate(
  24. new anchor.BN(1234),
  25. new anchor.BN(4321),
  26. {
  27. accounts: {
  28. foo: {
  29. dummyA: dummyA.publicKey,
  30. },
  31. bar: {
  32. dummyB: dummyB.publicKey,
  33. },
  34. },
  35. }
  36. );
  37. const dummyAAccount = await program.account.dummyA(dummyA.publicKey);
  38. const dummyBAccount = await program.account.dummyB(dummyB.publicKey);
  39. assert.ok(dummyAAccount.data.eq(new anchor.BN(1234)));
  40. assert.ok(dummyBAccount.data.eq(new anchor.BN(4321)));
  41. });
  42. });