Add getAccountInfo

This commit is contained in:
Michael Vines
2018-09-20 15:08:52 -07:00
parent da2496872b
commit 7148b0f7d8
4 changed files with 100 additions and 1 deletions

View File

@ -10,7 +10,7 @@ type RpcRequest = {
type RpcResponseError = {
message: string;
}
type RpcResponseResult = boolean | string | number;
type RpcResponseResult = any;
type RpcResponse = {
error: ?RpcResponseError;
result: ?RpcResponseResult;

View File

@ -16,6 +16,7 @@ test('pay', () => {
123,
);
console.log('Pay:', transaction);
// TODO: Validate transaction contents
transaction = BudgetProgram.pay(
from.publicKey,
@ -25,6 +26,7 @@ test('pay', () => {
BudgetProgram.signatureCondition(from.publicKey),
);
console.log('After:', transaction);
// TODO: Validate transaction contents
transaction = BudgetProgram.pay(
from.publicKey,
@ -35,5 +37,6 @@ test('pay', () => {
BudgetProgram.timestampCondition(from.publicKey, new Date()),
);
console.log('Or:', transaction);
// TODO: Validate transaction contents
});

View File

@ -17,6 +17,24 @@ const errorResponse = {
};
test('get account info - error', () => {
const account = new Account();
const connection = new Connection(url);
mockRpc.push([
url,
{
method: 'getAccountInfo',
params: [account.publicKey],
},
errorResponse,
]);
expect(connection.getAccountInfo(account.publicKey))
.rejects.toThrow(errorMessage);
});
test('get balance', async () => {
const account = new Account();
const connection = new Connection(url);
@ -176,6 +194,31 @@ test('request airdrop', async () => {
const balance = await connection.getBalance(account.publicKey);
expect(balance).toBe(42);
mockRpc.push([
url,
{
method: 'getAccountInfo',
params: [account.publicKey],
},
{
error: null,
result: {
contract_id: [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
],
tokens: 42,
userdata: [],
}
}
]);
const accountInfo = await connection.getAccountInfo(account.publicKey);
expect(accountInfo.tokens).toBe(42);
expect(accountInfo.userdata).toBe(null);
expect(accountInfo.programId).toBe(SystemProgram.programId);
});
test('request airdrop - error', () => {