fix: adapt tests to higher default transaction signature fee (#531)
This commit is contained in:
@ -228,7 +228,9 @@ declare module '@solana/web3.js' {
|
|||||||
|
|
||||||
constructor(opts?: TransactionCtorFields): Transaction;
|
constructor(opts?: TransactionCtorFields): Transaction;
|
||||||
add(
|
add(
|
||||||
...items: Array<Transaction | TransactionInstruction | TransactionInstructionCtorFields>
|
...items: Array<
|
||||||
|
Transaction | TransactionInstruction | TransactionInstructionCtorFields,
|
||||||
|
>
|
||||||
): Transaction;
|
): Transaction;
|
||||||
sign(...signers: Array<Account>): void;
|
sign(...signers: Array<Account>): void;
|
||||||
signPartial(...partialSigners: Array<PublicKey | Account>): void;
|
signPartial(...partialSigners: Array<PublicKey | Account>): void;
|
||||||
@ -272,4 +274,6 @@ declare module '@solana/web3.js' {
|
|||||||
|
|
||||||
// === src/util/testnet.js ===
|
// === src/util/testnet.js ===
|
||||||
declare export function testnetChannelEndpoint(channel?: string): string;
|
declare export function testnetChannelEndpoint(channel?: string): string;
|
||||||
|
|
||||||
|
declare export var SOL_LAMPORTS: number;
|
||||||
}
|
}
|
||||||
|
@ -701,7 +701,7 @@ export class Connection {
|
|||||||
);
|
);
|
||||||
const res = GetMinimumBalanceForRentExemptionRpcResult(unsafeRes);
|
const res = GetMinimumBalanceForRentExemptionRpcResult(unsafeRes);
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
console.warn("Unable to fetch minimum balance for rent exemption");
|
console.warn('Unable to fetch minimum balance for rent exemption');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
assert(typeof res.result !== 'undefined');
|
assert(typeof res.result !== 'undefined');
|
||||||
|
@ -15,3 +15,6 @@ export {
|
|||||||
sendAndConfirmRawTransaction,
|
sendAndConfirmRawTransaction,
|
||||||
} from './util/send-and-confirm-raw-transaction';
|
} from './util/send-and-confirm-raw-transaction';
|
||||||
export {testnetChannelEndpoint} from './util/testnet';
|
export {testnetChannelEndpoint} from './util/testnet';
|
||||||
|
|
||||||
|
// There are 2^34 lamports in one SOL
|
||||||
|
export const SOL_LAMPORTS = 17179869184;
|
||||||
|
@ -45,7 +45,9 @@ export class Loader {
|
|||||||
data: Array<number>,
|
data: Array<number>,
|
||||||
): Promise<PublicKey> {
|
): Promise<PublicKey> {
|
||||||
{
|
{
|
||||||
const balanceNeeded = await connection.getMinimumBalanceForRentExemption(data.length);
|
const balanceNeeded = await connection.getMinimumBalanceForRentExemption(
|
||||||
|
data.length,
|
||||||
|
);
|
||||||
const transaction = SystemProgram.createAccount(
|
const transaction = SystemProgram.createAccount(
|
||||||
payer.publicKey,
|
payer.publicKey,
|
||||||
program.publicKey,
|
program.publicKey,
|
||||||
@ -126,7 +128,7 @@ export class Loader {
|
|||||||
const transaction = new Transaction().add({
|
const transaction = new Transaction().add({
|
||||||
keys: [
|
keys: [
|
||||||
{pubkey: program.publicKey, isSigner: true, isDebitable: true},
|
{pubkey: program.publicKey, isSigner: true, isDebitable: true},
|
||||||
{pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isDebitable: false}
|
{pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isDebitable: false},
|
||||||
],
|
],
|
||||||
programId,
|
programId,
|
||||||
data,
|
data,
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
BpfLoader,
|
BpfLoader,
|
||||||
Transaction,
|
Transaction,
|
||||||
sendAndConfirmTransaction,
|
sendAndConfirmTransaction,
|
||||||
|
SOL_LAMPORTS,
|
||||||
} from '../src';
|
} from '../src';
|
||||||
import {mockRpcEnabled} from './__mocks__/node-fetch';
|
import {mockRpcEnabled} from './__mocks__/node-fetch';
|
||||||
import {url} from './url';
|
import {url} from './url';
|
||||||
@ -24,7 +25,7 @@ test('load BPF C program', async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const connection = new Connection(url);
|
const connection = new Connection(url);
|
||||||
const from = await newAccountWithLamports(connection, 1024);
|
const from = await newAccountWithLamports(connection, SOL_LAMPORTS);
|
||||||
const data = await fs.readFile('test/fixtures/noop-c/noop.so');
|
const data = await fs.readFile('test/fixtures/noop-c/noop.so');
|
||||||
const programId = await BpfLoader.load(connection, from, data);
|
const programId = await BpfLoader.load(connection, from, data);
|
||||||
const transaction = new Transaction().add({
|
const transaction = new Transaction().add({
|
||||||
@ -41,7 +42,7 @@ test('load BPF Rust program', async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const connection = new Connection(url);
|
const connection = new Connection(url);
|
||||||
const from = await newAccountWithLamports(connection, 100000);
|
const from = await newAccountWithLamports(connection, SOL_LAMPORTS);
|
||||||
const data = await fs.readFile(
|
const data = await fs.readFile(
|
||||||
'test/fixtures/noop-rust/solana_bpf_rust_noop.so',
|
'test/fixtures/noop-rust/solana_bpf_rust_noop.so',
|
||||||
);
|
);
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
Loader,
|
Loader,
|
||||||
SystemProgram,
|
SystemProgram,
|
||||||
sendAndConfirmTransaction,
|
sendAndConfirmTransaction,
|
||||||
|
SOL_LAMPORTS,
|
||||||
} from '../src';
|
} from '../src';
|
||||||
import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../src/timing';
|
import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../src/timing';
|
||||||
import {mockRpc, mockRpcEnabled} from './__mocks__/node-fetch';
|
import {mockRpc, mockRpcEnabled} from './__mocks__/node-fetch';
|
||||||
@ -54,8 +55,8 @@ test('get program accounts', async () => {
|
|||||||
const account0 = new Account();
|
const account0 = new Account();
|
||||||
const account1 = new Account();
|
const account1 = new Account();
|
||||||
const programId = new Account();
|
const programId = new Account();
|
||||||
await connection.requestAirdrop(account0.publicKey, 42);
|
await connection.requestAirdrop(account0.publicKey, SOL_LAMPORTS);
|
||||||
await connection.requestAirdrop(account1.publicKey, 84);
|
await connection.requestAirdrop(account1.publicKey, 0.5 * SOL_LAMPORTS);
|
||||||
|
|
||||||
let transaction = SystemProgram.assign(
|
let transaction = SystemProgram.assign(
|
||||||
account0.publicKey,
|
account0.publicKey,
|
||||||
@ -79,9 +80,9 @@ test('get program accounts', async () => {
|
|||||||
account1.publicKey.toBase58(),
|
account1.publicKey.toBase58(),
|
||||||
]).toEqual(expect.arrayContaining([element[0]]));
|
]).toEqual(expect.arrayContaining([element[0]]));
|
||||||
if (element[0] == account0.publicKey) {
|
if (element[0] == account0.publicKey) {
|
||||||
expect(element[1].lamports).toBe(42 - feeCalculator.lamportsPerSignature);
|
expect(element[1].lamports).toBe(SOL_LAMPORTS - feeCalculator.lamportsPerSignature);
|
||||||
} else {
|
} else {
|
||||||
expect(element[1].lamports).toBe(84 - feeCalculator.lamportsPerSignature);
|
expect(element[1].lamports).toBe(0.5 * SOL_LAMPORTS- feeCalculator.lamportsPerSignature);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -629,8 +630,8 @@ test('multi-instruction transaction', async () => {
|
|||||||
const accountTo = new Account();
|
const accountTo = new Account();
|
||||||
const connection = new Connection(url);
|
const connection = new Connection(url);
|
||||||
|
|
||||||
await connection.requestAirdrop(accountFrom.publicKey, 100000);
|
await connection.requestAirdrop(accountFrom.publicKey, SOL_LAMPORTS);
|
||||||
expect(await connection.getBalance(accountFrom.publicKey)).toBe(100000);
|
expect(await connection.getBalance(accountFrom.publicKey)).toBe(SOL_LAMPORTS);
|
||||||
|
|
||||||
await connection.requestAirdrop(accountTo.publicKey, 21);
|
await connection.requestAirdrop(accountTo.publicKey, 21);
|
||||||
expect(await connection.getBalance(accountTo.publicKey)).toBe(21);
|
expect(await connection.getBalance(accountTo.publicKey)).toBe(21);
|
||||||
@ -663,11 +664,11 @@ test('multi-instruction transaction', async () => {
|
|||||||
Ok: null,
|
Ok: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
// accountFrom may have less than 100000 due to transaction fees
|
// accountFrom may have less than SOL_LAMPORTS due to transaction fees
|
||||||
expect(await connection.getBalance(accountFrom.publicKey)).toBeGreaterThan(0);
|
expect(await connection.getBalance(accountFrom.publicKey)).toBeGreaterThan(0);
|
||||||
expect(
|
expect(
|
||||||
await connection.getBalance(accountFrom.publicKey),
|
await connection.getBalance(accountFrom.publicKey),
|
||||||
).toBeLessThanOrEqual(100000);
|
).toBeLessThanOrEqual(SOL_LAMPORTS);
|
||||||
|
|
||||||
expect(await connection.getBalance(accountTo.publicKey)).toBe(21);
|
expect(await connection.getBalance(accountTo.publicKey)).toBe(21);
|
||||||
});
|
});
|
||||||
@ -689,7 +690,7 @@ test('account change notification', async () => {
|
|||||||
mockCallback,
|
mockCallback,
|
||||||
);
|
);
|
||||||
|
|
||||||
await connection.requestAirdrop(owner.publicKey, 100000);
|
await connection.requestAirdrop(owner.publicKey, SOL_LAMPORTS);
|
||||||
await Loader.load(connection, owner, programAccount, BpfLoader.programId, [
|
await Loader.load(connection, owner, programAccount, BpfLoader.programId, [
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
@ -743,7 +744,7 @@ test('program account change notification', async () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
await connection.requestAirdrop(owner.publicKey, 100000);
|
await connection.requestAirdrop(owner.publicKey, SOL_LAMPORTS);
|
||||||
await Loader.load(connection, owner, programAccount, BpfLoader.programId, [
|
await Loader.load(connection, owner, programAccount, BpfLoader.programId, [
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import {Account, Connection, SystemProgram} from '../src';
|
import {Account, Connection, SystemProgram, SOL_LAMPORTS} from '../src';
|
||||||
import {mockRpc, mockRpcEnabled} from './__mocks__/node-fetch';
|
import {mockRpc, mockRpcEnabled} from './__mocks__/node-fetch';
|
||||||
import {mockGetRecentBlockhash} from './mockrpc/get-recent-blockhash';
|
import {mockGetRecentBlockhash} from './mockrpc/get-recent-blockhash';
|
||||||
import {url} from './url';
|
import {url} from './url';
|
||||||
@ -20,7 +20,7 @@ test('transaction-payer', async () => {
|
|||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
method: 'requestAirdrop',
|
method: 'requestAirdrop',
|
||||||
params: [accountPayer.publicKey.toBase58(), 100],
|
params: [accountPayer.publicKey.toBase58(), SOL_LAMPORTS],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
@ -28,7 +28,7 @@ test('transaction-payer', async () => {
|
|||||||
'0WE5w4B7v59x6qjyC4FbG2FEKYKQfvsJwqSxNVmtMjT8TQ31hsZieDHcSgqzxiAoTL56n2w5TncjqEKjLhtF4Vk',
|
'0WE5w4B7v59x6qjyC4FbG2FEKYKQfvsJwqSxNVmtMjT8TQ31hsZieDHcSgqzxiAoTL56n2w5TncjqEKjLhtF4Vk',
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
await connection.requestAirdrop(accountPayer.publicKey, 100);
|
await connection.requestAirdrop(accountPayer.publicKey, SOL_LAMPORTS);
|
||||||
|
|
||||||
mockRpc.push([
|
mockRpc.push([
|
||||||
url,
|
url,
|
||||||
@ -141,7 +141,7 @@ test('transaction-payer', async () => {
|
|||||||
// (exact amount less depends on the current cluster fees)
|
// (exact amount less depends on the current cluster fees)
|
||||||
const balance = await connection.getBalance(accountPayer.publicKey);
|
const balance = await connection.getBalance(accountPayer.publicKey);
|
||||||
expect(balance).toBeGreaterThan(0);
|
expect(balance).toBeGreaterThan(0);
|
||||||
expect(balance).toBeLessThanOrEqual(100);
|
expect(balance).toBeLessThanOrEqual(SOL_LAMPORTS);
|
||||||
|
|
||||||
// accountFrom should have exactly 2, since it didn't pay for the transaction
|
// accountFrom should have exactly 2, since it didn't pay for the transaction
|
||||||
mockRpc.push([
|
mockRpc.push([
|
||||||
|
Reference in New Issue
Block a user