Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair the tests for @solana/compat since adding fromLegacyTransactionInstruction() #46

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions packages/compat/src/__tests__/instruction-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import { PublicKey, TransactionInstruction } from '@solana/web3.js';
import { fromLegacyPublicKey } from '../address';
import { fromLegacyTransactionInstruction } from '../instruction';

function toLegacyByteArrayAppropriateForPlatform<TArrayBuffer extends ArrayBufferLike>(
data: WithImplicitCoercion<TArrayBuffer>,
): Buffer<TArrayBuffer> {
if (__NODEJS__) {
return Buffer.from(data);
} else {
return new Uint8Array(data as TArrayBuffer) as Buffer<TArrayBuffer>;
}
}

describe('fromLegacyTransactionInstruction', () => {
it('converts a basic TransactionInstruction', () => {
const programId = new Uint8Array([1, 2, 3, 4]);
Expand All @@ -20,7 +30,7 @@ describe('fromLegacyTransactionInstruction', () => {
const data = new Uint8Array([10, 20, 30]);

const instruction = new TransactionInstruction({
data: Buffer.from(data),
data: toLegacyByteArrayAppropriateForPlatform(data),
keys,
programId: new PublicKey(programId),
});
Expand Down Expand Up @@ -51,7 +61,7 @@ describe('fromLegacyTransactionInstruction', () => {
const data = new Uint8Array([10, 20, 30]);

const instruction = new TransactionInstruction({
data: Buffer.from(data),
data: toLegacyByteArrayAppropriateForPlatform(data),
keys,
programId: new PublicKey(programId),
});
Expand All @@ -73,7 +83,7 @@ describe('fromLegacyTransactionInstruction', () => {
const data = new Uint8Array([10, 20, 30]);

const instruction = new TransactionInstruction({
data: Buffer.from(data),
data: toLegacyByteArrayAppropriateForPlatform(data),
keys,
programId: new PublicKey(programId),
});
Expand All @@ -95,7 +105,7 @@ describe('fromLegacyTransactionInstruction', () => {
const data = new Uint8Array([10, 20, 30]);

const instruction = new TransactionInstruction({
data: Buffer.from(data),
data: toLegacyByteArrayAppropriateForPlatform(data),
keys,
programId: new PublicKey(programId),
});
Expand All @@ -110,7 +120,7 @@ describe('fromLegacyTransactionInstruction', () => {
const data = new Uint8Array([40, 50, 60]);

const instruction = new TransactionInstruction({
data: Buffer.from(data),
data: toLegacyByteArrayAppropriateForPlatform(data),
keys: [],
programId: new PublicKey(programId),
});
Expand All @@ -136,7 +146,7 @@ describe('fromLegacyTransactionInstruction', () => {
const data = new Uint8Array([70, 80, 90]);

const instruction = new TransactionInstruction({
data: Buffer.from(data),
data: toLegacyByteArrayAppropriateForPlatform(data),
keys,
programId: new PublicKey(programId),
});
Expand Down Expand Up @@ -170,7 +180,7 @@ describe('fromLegacyTransactionInstruction', () => {
];

const instruction = new TransactionInstruction({
data: Buffer.from(new Uint8Array()),
data: toLegacyByteArrayAppropriateForPlatform(new Uint8Array()),
keys,
programId: new PublicKey(programId),
});
Expand Down
4 changes: 4 additions & 0 deletions packages/compat/src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare const __BROWSER__: boolean;
declare const __DEV__: boolean;
declare const __NODEJS__: boolean;
declare const __REACTNATIVE__: boolean;
Loading