feat: add getSlotLeader()/getClusterNodes()

This commit is contained in:
Michael Vines
2019-04-23 09:53:26 -07:00
parent 5f2bcd5200
commit a2cd9180b5
8 changed files with 177 additions and 43 deletions

View File

@ -64,6 +64,64 @@ test('get balance', async () => {
expect(balance).toBeGreaterThanOrEqual(0);
});
test('get slot leader', async () => {
const connection = new Connection(url);
mockRpc.push([
url,
{
method: 'getSlotLeader',
},
{
error: null,
result: '11111111111111111111111111111111',
},
]);
const slotLeader = await connection.getSlotLeader();
if (mockRpcEnabled) {
expect(slotLeader).toBe('11111111111111111111111111111111');
} else {
// No idea what the correct slotLeader value should be on a live cluster, so
// just check the type
expect(typeof slotLeader).toBe('string');
}
});
test('get cluster nodes', async () => {
const connection = new Connection(url);
mockRpc.push([
url,
{
method: 'getClusterNodes',
},
{
error: null,
result: [
{
id: '11111111111111111111111111111111',
gossip: '127.0.0.0:1234',
tpu: '127.0.0.0:1235',
rpc: null,
},
],
},
]);
const clusterNodes = await connection.getClusterNodes();
if (mockRpcEnabled) {
expect(clusterNodes).toHaveLength(1);
expect(clusterNodes[0].id).toBe('11111111111111111111111111111111');
expect(typeof clusterNodes[0].gossip).toBe('string');
expect(typeof clusterNodes[0].tpu).toBe('string');
expect(clusterNodes[0].rpc).toBeNull();
} else {
// There should be at least one node (the node that we're talking to)
expect(clusterNodes.length).toBeGreaterThan(0);
}
});
test('confirm transaction - error', () => {
const connection = new Connection(url);

View File

@ -23,7 +23,11 @@ test('load native program', async () => {
const connection = new Connection(url);
const from = await newAccountWithLamports(connection, 1024);
const programId = await NativeLoader.load(connection, from, 'solana_noop_program');
const programId = await NativeLoader.load(
connection,
from,
'solana_noop_program',
);
const transaction = new Transaction().add({
keys: [{pubkey: from.publicKey, isSigner: true}],
programId,

View File

@ -10,7 +10,11 @@ test('signPartial', () => {
const account1 = new Account();
const account2 = new Account();
const recentBlockhash = account1.publicKey.toBase58(); // Fake recentBlockhash
const transfer = SystemProgram.transfer(account1.publicKey, account2.publicKey, 123);
const transfer = SystemProgram.transfer(
account1.publicKey,
account2.publicKey,
123,
);
const transaction = new Transaction({recentBlockhash}).add(transfer);
transaction.sign(account1, account2);
@ -27,10 +31,21 @@ test('transfer signatures', () => {
const account1 = new Account();
const account2 = new Account();
const recentBlockhash = account1.publicKey.toBase58(); // Fake recentBlockhash
const transfer1 = SystemProgram.transfer(account1.publicKey, account2.publicKey, 123);
const transfer2 = SystemProgram.transfer(account2.publicKey, account1.publicKey, 123);
const transfer1 = SystemProgram.transfer(
account1.publicKey,
account2.publicKey,
123,
);
const transfer2 = SystemProgram.transfer(
account2.publicKey,
account1.publicKey,
123,
);
const orgTransaction = new Transaction({recentBlockhash}).add(transfer1, transfer2);
const orgTransaction = new Transaction({recentBlockhash}).add(
transfer1,
transfer2,
);
orgTransaction.sign(account1, account2);
const newTransaction = new Transaction({