Skip to content

Commit

Permalink
Create metadata tests passing with new program arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbosborn committed Apr 4, 2022
1 parent c00a7a9 commit ef972e8
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions tests/test-v1.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -27,17 +27,19 @@ 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());

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({
Expand All @@ -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);
}
});
Expand Down Expand Up @@ -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;
}
});

Expand Down

0 comments on commit ef972e8

Please sign in to comment.