fix: wait for the next lastId before sending a new transaction
This commit is contained in:
@ -6,6 +6,7 @@ import {
|
||||
SystemProgram,
|
||||
} from '../src';
|
||||
import {mockRpc, mockRpcEnabled} from './__mocks__/node-fetch';
|
||||
import {mockGetLastId} from './mockrpc/getlastid';
|
||||
import {url} from './url';
|
||||
|
||||
if (!mockRpcEnabled) {
|
||||
@ -117,18 +118,7 @@ test('get transaction count', async () => {
|
||||
test('get last Id', async () => {
|
||||
const connection = new Connection(url);
|
||||
|
||||
mockRpc.push([
|
||||
url,
|
||||
{
|
||||
method: 'getLastId',
|
||||
params: [],
|
||||
},
|
||||
{
|
||||
error: null,
|
||||
result: '2BjEqiiT43J6XskiHdz7aoocjPeWkCPiKD72SiFQsrA2',
|
||||
}
|
||||
]
|
||||
);
|
||||
mockGetLastId();
|
||||
|
||||
const lastId = await connection.getLastId();
|
||||
expect(lastId.length).toBeGreaterThanOrEqual(43);
|
||||
@ -283,18 +273,7 @@ test('transaction', async () => {
|
||||
await connection.requestAirdrop(accountTo.publicKey, 21);
|
||||
expect(await connection.getBalance(accountTo.publicKey)).toBe(21);
|
||||
|
||||
mockRpc.push([
|
||||
url,
|
||||
{
|
||||
method: 'getLastId',
|
||||
params: [],
|
||||
},
|
||||
{
|
||||
error: null,
|
||||
result: '2BjEqiiT43J6XskiHdz7aoocjPeWkCPiKD72SiFQsrA2',
|
||||
}
|
||||
]
|
||||
);
|
||||
mockGetLastId();
|
||||
mockRpc.push([
|
||||
url,
|
||||
{
|
||||
|
23
web3.js/test/mockrpc/getlastid.js
Normal file
23
web3.js/test/mockrpc/getlastid.js
Normal file
@ -0,0 +1,23 @@
|
||||
// @flow
|
||||
|
||||
import {
|
||||
Account,
|
||||
} from '../../src';
|
||||
import {url} from '../url';
|
||||
import {mockRpc} from '../__mocks__/node-fetch';
|
||||
|
||||
export function mockGetLastId() {
|
||||
const lastId = new Account();
|
||||
|
||||
mockRpc.push([
|
||||
url,
|
||||
{
|
||||
method: 'getLastId',
|
||||
params: [],
|
||||
},
|
||||
{
|
||||
error: null,
|
||||
result: lastId.publicKey.toBase58(),
|
||||
}
|
||||
]);
|
||||
}
|
@ -10,26 +10,13 @@ import {SYSTEM_TOKEN_PROGRAM_ID} from '../src/token-program';
|
||||
import {mockRpc, mockRpcEnabled} from './__mocks__/node-fetch';
|
||||
import {url} from './url';
|
||||
import {newAccountWithTokens} from './new-account-with-tokens';
|
||||
import {mockGetLastId} from './mockrpc/getlastid';
|
||||
|
||||
if (!mockRpcEnabled) {
|
||||
// The default of 5 seconds is too slow for live testing sometimes
|
||||
jest.setTimeout(10000);
|
||||
}
|
||||
|
||||
function mockGetLastId() {
|
||||
mockRpc.push([
|
||||
url,
|
||||
{
|
||||
method: 'getLastId',
|
||||
params: [],
|
||||
},
|
||||
{
|
||||
error: null,
|
||||
result: '2BjEqiiT43J6XskiHdz7aoocjPeWkCPiKD72SiFQsrA2',
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
function mockGetSignatureStatus(result: string = 'Confirmed') {
|
||||
mockRpc.push([
|
||||
url,
|
||||
|
Reference in New Issue
Block a user