diff --git a/tests/test-v1.ts b/tests/test-v1.ts index 2b302af..cf551f4 100644 --- a/tests/test-v1.ts +++ b/tests/test-v1.ts @@ -1,5 +1,5 @@ import * as anchor from '@project-serum/anchor'; -import { AnchorError, Program } from '@project-serum/anchor'; +import { AnchorError, Idl, Program, Provider } from '@project-serum/anchor'; import * as web3 from '@solana/web3.js'; import chai, { expect } from 'chai'; import chaiAsPromised from 'chai-as-promised'; @@ -27,6 +27,7 @@ import { ENCRYPTION_OVERHEAD_BYTES } from '../src/utils/ecdh-encryption'; import { NONCE_SIZE_BYTES } from '../src/utils/nonce-generator'; import { randomInt } from 'crypto'; import { CountDownLatch } from '../src/utils/countdown-latch'; +import { idl, programs, Wallet_ } from '../src/utils'; chai.use(chaiAsPromised); anchor.setProvider(anchor.Provider.local()); @@ -34,10 +35,11 @@ anchor.setProvider(anchor.Provider.local()); describe('Protocol v1 test', () => { const program: anchor.Program = anchor.workspace.Dialect; const connection = program.provider.connection; + console.log('program', program); describe('Metadata tests', () => { - let owner: web3.Keypair; - let writer: web3.Keypair; + let owner: Program; + let writer: Program; beforeEach(async () => { owner = await createUser({ @@ -52,8 +54,8 @@ describe('Protocol v1 test', () => { it('Create user metadata object(s)', async () => { for (const member of [owner, writer]) { - const metadata = await createMetadata(program, member); - const gottenMetadata = await getMetadata(program, member.publicKey); + const metadata = await createMetadata(member); + const gottenMetadata = await getMetadata(member, member.provider.wallet.publicKey); expect(metadata).to.be.deep.eq(gottenMetadata); } }); @@ -982,18 +984,34 @@ describe('Protocol v1 test', () => { createMeta: true, }, ) { - const user = web3.Keypair.generate(); + const keypair = web3.Keypair.generate(); + const wallet = Wallet_.embedded(keypair.secretKey); + const RPC_URL = process.env.RPC_URL || 'http://localhost:8899'; + const dialectConnection = new web3.Connection(RPC_URL, 'recent'); + const dialectProvider = new Provider( + dialectConnection, + wallet, + Provider.defaultOptions(), + ); + // @ts-ignore + const NETWORK_NAME = 'localnet'; + const DIALECT_PROGRAM_ADDRESS = programs[NETWORK_NAME].programAddress; + const program = new Program( + idl as Idl, + new web3.PublicKey(DIALECT_PROGRAM_ADDRESS), + dialectProvider, + ); if (requestAirdrop) { const airDropRequest = await connection.requestAirdrop( - user.publicKey, + wallet.publicKey, 10 * web3.LAMPORTS_PER_SOL, ); await connection.confirmTransaction(airDropRequest); } if (createMeta) { - await createMetadata(program, user); + await createMetadata(program); } - return user; + return program; } });