test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {
  2. Connection,
  3. Keypair,
  4. sendAndConfirmTransaction,
  5. Transaction,
  6. TransactionInstruction,
  7. } from '@solana/web3.js';
  8. function createKeypairFromFile(path: string): Keypair {
  9. return Keypair.fromSecretKey(
  10. Buffer.from(JSON.parse(require('fs').readFileSync(path, "utf-8")))
  11. )
  12. };
  13. describe("hello-solana", () => {
  14. // Loading these from local files for development
  15. //
  16. const connection = new Connection(`http://localhost:8899`, 'confirmed');
  17. const payer = createKeypairFromFile(require('os').homedir() + '/.config/solana/id.json');
  18. const program = createKeypairFromFile('./program/target/so/program-keypair.json');
  19. it("Say hello!", async () => {
  20. // We set up our instruction first.
  21. //
  22. let ix = new TransactionInstruction({
  23. keys: [
  24. {pubkey: payer.publicKey, isSigner: true, isWritable: true}
  25. ],
  26. programId: program.publicKey,
  27. data: Buffer.alloc(0), // No data
  28. });
  29. // Now we send the transaction over RPC
  30. //
  31. await sendAndConfirmTransaction(
  32. connection,
  33. new Transaction().add(ix), // Add our instruction (you can add more than one)
  34. [payer]
  35. );
  36. });
  37. });