2018-10-23 20:56:54 -07:00
|
|
|
// @flow
|
|
|
|
|
2018-10-25 10:41:18 -07:00
|
|
|
import fs from 'mz/fs';
|
|
|
|
|
2018-10-23 20:56:54 -07:00
|
|
|
import {
|
|
|
|
Connection,
|
|
|
|
BpfLoader,
|
|
|
|
Transaction,
|
|
|
|
sendAndConfirmTransaction,
|
|
|
|
} from '../src';
|
|
|
|
import {mockRpcEnabled} from './__mocks__/node-fetch';
|
|
|
|
import {url} from './url';
|
2019-03-05 17:52:13 -08:00
|
|
|
import {newAccountWithLamports} from './new-account-with-lamports';
|
2018-10-23 20:56:54 -07:00
|
|
|
|
|
|
|
if (!mockRpcEnabled) {
|
|
|
|
// The default of 5 seconds is too slow for live testing sometimes
|
2019-05-10 14:16:35 -07:00
|
|
|
jest.setTimeout(120000);
|
2018-10-23 20:56:54 -07:00
|
|
|
}
|
|
|
|
|
2019-10-22 15:16:12 -07:00
|
|
|
const NUM_RETRIES = 100; /* allow some number of retries */
|
|
|
|
|
2019-05-10 14:16:35 -07:00
|
|
|
test('load BPF C program', async () => {
|
2018-10-23 20:56:54 -07:00
|
|
|
if (mockRpcEnabled) {
|
|
|
|
console.log('non-live test skipped');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-10 14:16:35 -07:00
|
|
|
const data = await fs.readFile('test/fixtures/noop-c/noop.so');
|
2019-10-22 15:16:12 -07:00
|
|
|
|
|
|
|
const connection = new Connection(url);
|
|
|
|
const [, feeCalculator] = await connection.getRecentBlockhash();
|
|
|
|
const fees =
|
|
|
|
feeCalculator.lamportsPerSignature *
|
|
|
|
(BpfLoader.getMinNumSignatures(data.length) + NUM_RETRIES);
|
|
|
|
const from = await newAccountWithLamports(connection, fees);
|
|
|
|
|
2019-05-10 14:16:35 -07:00
|
|
|
const programId = await BpfLoader.load(connection, from, data);
|
|
|
|
const transaction = new Transaction().add({
|
2019-11-06 10:42:01 -07:00
|
|
|
keys: [{pubkey: from.publicKey, isSigner: true, isWritable: true}],
|
2019-05-10 14:16:35 -07:00
|
|
|
programId,
|
|
|
|
});
|
|
|
|
await sendAndConfirmTransaction(connection, transaction, from);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('load BPF Rust program', async () => {
|
|
|
|
if (mockRpcEnabled) {
|
|
|
|
console.log('non-live test skipped');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-23 10:44:55 -06:00
|
|
|
const data = await fs.readFile(
|
|
|
|
'test/fixtures/noop-rust/solana_bpf_rust_noop.so',
|
|
|
|
);
|
2019-10-22 15:16:12 -07:00
|
|
|
|
|
|
|
const connection = new Connection(url);
|
|
|
|
const [, feeCalculator] = await connection.getRecentBlockhash();
|
|
|
|
const fees =
|
|
|
|
feeCalculator.lamportsPerSignature *
|
|
|
|
(BpfLoader.getMinNumSignatures(data.length) + NUM_RETRIES);
|
|
|
|
const from = await newAccountWithLamports(connection, fees);
|
|
|
|
|
2018-10-25 10:41:18 -07:00
|
|
|
const programId = await BpfLoader.load(connection, from, data);
|
2018-10-23 20:56:54 -07:00
|
|
|
const transaction = new Transaction().add({
|
2019-11-06 10:42:01 -07:00
|
|
|
keys: [{pubkey: from.publicKey, isSigner: true, isWritable: true}],
|
2018-10-23 20:56:54 -07:00
|
|
|
programId,
|
|
|
|
});
|
2018-11-18 08:48:14 -08:00
|
|
|
await sendAndConfirmTransaction(connection, transaction, from);
|
2018-10-23 20:56:54 -07:00
|
|
|
});
|