misc.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const anchor = require("@project-serum/anchor");
  2. const serumCmn = require("@project-serum/common");
  3. const assert = require("assert");
  4. describe("misc", () => {
  5. // Configure the client to use the local cluster.
  6. anchor.setProvider(anchor.Provider.env());
  7. const program = anchor.workspace.Misc;
  8. it("Can allocate extra space for a state constructor", async () => {
  9. const tx = await program.state.rpc.new();
  10. const addr = await program.state.address();
  11. const state = await program.state();
  12. const accountInfo = await program.provider.connection.getAccountInfo(addr);
  13. assert.ok(state.v.equals(Buffer.from([])));
  14. assert.ok(accountInfo.data.length === 99);
  15. });
  16. it("Can use u128 and i128", async () => {
  17. const data = new anchor.web3.Account();
  18. const tx = await program.rpc.initialize(
  19. new anchor.BN(1234),
  20. new anchor.BN(22),
  21. {
  22. accounts: {
  23. data: data.publicKey,
  24. rent: anchor.web3.SYSVAR_RENT_PUBKEY,
  25. },
  26. signers: [data],
  27. instructions: [await program.account.data.createInstruction(data)],
  28. }
  29. );
  30. const dataAccount = await program.account.data(data.publicKey);
  31. assert.ok(dataAccount.udata.eq(new anchor.BN(1234)));
  32. assert.ok(dataAccount.idata.eq(new anchor.BN(22)));
  33. });
  34. it("Can embed programs into genesis from the Anchor.toml", async () => {
  35. const pid = new anchor.web3.PublicKey(
  36. "FtMNMKp9DZHKWUyVAsj3Q5QV8ow4P3fUPP7ZrWEQJzKr"
  37. );
  38. let accInfo = await anchor.getProvider().connection.getAccountInfo(pid);
  39. assert.ok(accInfo.executable);
  40. });
  41. });