feat: return null when account info not found
This commit is contained in:
committed by
Michael Vines
parent
0fcb1f6f56
commit
7989c10b7a
@ -25,7 +25,7 @@ const errorResponse = {
|
||||
result: undefined,
|
||||
};
|
||||
|
||||
test('get account info - error', () => {
|
||||
test('get account info - not found', async () => {
|
||||
const account = new Account();
|
||||
const connection = new Connection(url);
|
||||
|
||||
@ -35,12 +35,18 @@ test('get account info - error', () => {
|
||||
method: 'getAccountInfo',
|
||||
params: [account.publicKey.toBase58()],
|
||||
},
|
||||
errorResponse,
|
||||
{
|
||||
error: null,
|
||||
result: {
|
||||
context: {
|
||||
slot: 11,
|
||||
},
|
||||
value: null,
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
return expect(connection.getAccountInfo(account.publicKey)).rejects.toThrow(
|
||||
errorMessage,
|
||||
);
|
||||
expect(await connection.getAccountInfo(account.publicKey)).toBeNull();
|
||||
});
|
||||
|
||||
test('get program accounts', async () => {
|
||||
@ -820,6 +826,10 @@ test('request airdrop', async () => {
|
||||
]);
|
||||
|
||||
const accountInfo = await connection.getAccountInfo(account.publicKey);
|
||||
if (accountInfo === null) {
|
||||
expect(accountInfo).not.toBeNull();
|
||||
return;
|
||||
}
|
||||
expect(accountInfo.lamports).toBe(minimumAmount + 42);
|
||||
expect(accountInfo.data).toHaveLength(0);
|
||||
expect(accountInfo.owner).toEqual(SystemProgram.programId);
|
||||
|
@ -129,6 +129,10 @@ test('create and query nonce account', async () => {
|
||||
nonceAccount.publicKey,
|
||||
'recent',
|
||||
);
|
||||
if (nonceAccountData === null) {
|
||||
expect(nonceAccountData).not.toBeNull();
|
||||
return;
|
||||
}
|
||||
expect(nonceAccountData.authorizedPubkey).toEqual(from.publicKey);
|
||||
expect(bs58.decode(nonceAccountData.nonce).length).toBeGreaterThan(30);
|
||||
});
|
||||
|
@ -224,7 +224,17 @@ test('live Nonce actions', async () => {
|
||||
expect(nonceBalance).toEqual(minimumAmount);
|
||||
|
||||
const nonceQuery1 = await connection.getNonce(nonceAccount.publicKey);
|
||||
if (nonceQuery1 === null) {
|
||||
expect(nonceQuery1).not.toBeNull();
|
||||
return;
|
||||
}
|
||||
|
||||
const nonceQuery2 = await connection.getNonce(nonceAccount.publicKey);
|
||||
if (nonceQuery2 === null) {
|
||||
expect(nonceQuery2).not.toBeNull();
|
||||
return;
|
||||
}
|
||||
|
||||
expect(nonceQuery1.nonce).toEqual(nonceQuery2.nonce);
|
||||
|
||||
// Wait for blockhash to advance
|
||||
@ -238,6 +248,10 @@ test('live Nonce actions', async () => {
|
||||
);
|
||||
await sendAndConfirmRecentTransaction(connection, advanceNonce, from);
|
||||
const nonceQuery3 = await connection.getNonce(nonceAccount.publicKey);
|
||||
if (nonceQuery3 === null) {
|
||||
expect(nonceQuery3).not.toBeNull();
|
||||
return;
|
||||
}
|
||||
expect(nonceQuery1.nonce).not.toEqual(nonceQuery3.nonce);
|
||||
const nonce = nonceQuery3.nonce;
|
||||
|
||||
|
Reference in New Issue
Block a user