misc.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. it("Can use the executable attribtue", async () => {
  42. await program.rpc.testExecutable({
  43. accounts: {
  44. program: program.programId,
  45. },
  46. });
  47. await assert.rejects(
  48. async () => {
  49. await program.rpc.testExecutable({
  50. accounts: {
  51. program: program.provider.wallet.publicKey,
  52. },
  53. });
  54. },
  55. (err) => {
  56. return true;
  57. }
  58. );
  59. });
  60. });