feat: support rpc method getSignaturesByAddres
This commit is contained in:
committed by
Michael Vines
parent
3362ac06b5
commit
db3475bcdf
@ -1011,6 +1011,112 @@ describe('Connection', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('get signatures for address', async () => {
|
||||
const connection = new Connection(url);
|
||||
|
||||
await mockRpcResponse({
|
||||
method: 'getSlot',
|
||||
params: [],
|
||||
value: 1,
|
||||
});
|
||||
|
||||
while ((await connection.getSlot()) <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await mockRpcResponse({
|
||||
method: 'getConfirmedBlock',
|
||||
params: [1],
|
||||
value: {
|
||||
blockTime: 1614281964,
|
||||
blockhash: '57zQNBZBEiHsCZFqsaY6h176ioXy5MsSLmcvHkEyaLGy',
|
||||
previousBlockhash: 'H5nJ91eGag3B5ZSRHZ7zG5ZwXJ6ywCt2hyR8xCsV7xMo',
|
||||
parentSlot: 0,
|
||||
transactions: [
|
||||
{
|
||||
meta: {
|
||||
fee: 10000,
|
||||
postBalances: [499260347380, 15298080, 1, 1, 1],
|
||||
preBalances: [499260357380, 15298080, 1, 1, 1],
|
||||
status: {Ok: null},
|
||||
err: null,
|
||||
},
|
||||
transaction: {
|
||||
message: {
|
||||
accountKeys: [
|
||||
'va12u4o9DipLEB2z4fuoHszroq1U9NcAB9aooFDPJSf',
|
||||
'57zQNBZBEiHsCZFqsaY6h176ioXy5MsSLmcvHkEyaLGy',
|
||||
'SysvarS1otHashes111111111111111111111111111',
|
||||
'SysvarC1ock11111111111111111111111111111111',
|
||||
'Vote111111111111111111111111111111111111111',
|
||||
],
|
||||
header: {
|
||||
numReadonlySignedAccounts: 0,
|
||||
numReadonlyUnsignedAccounts: 3,
|
||||
numRequiredSignatures: 2,
|
||||
},
|
||||
instructions: [
|
||||
{
|
||||
accounts: [1, 2, 3],
|
||||
data: '37u9WtQpcm6ULa3VtWDFAWoQc1hUvybPrA3dtx99tgHvvcE7pKRZjuGmn7VX2tC3JmYDYGG7',
|
||||
programIdIndex: 4,
|
||||
},
|
||||
],
|
||||
recentBlockhash: 'GeyAFFRY3WGpmam2hbgrKw4rbU2RKzfVLm5QLSeZwTZE',
|
||||
},
|
||||
signatures: [
|
||||
'w2Zeq8YkpyB463DttvfzARD7k9ZxGEwbsEw4boEK7jDp3pfoxZbTdLFSsEPhzXhpCcjGi2kHtHFobgX49MMhbWt',
|
||||
'4oCEqwGrMdBeMxpzuWiukCYqSfV4DsSKXSiVVCh1iJ6pS772X7y219JZP3mgqBz5PhsvprpKyhzChjYc3VSBQXzG',
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
// Find a block that has a transaction, usually Block 1
|
||||
let slot = 0;
|
||||
let address: PublicKey | undefined;
|
||||
let expectedSignature: string | undefined;
|
||||
while (!address || !expectedSignature) {
|
||||
slot++;
|
||||
const block = await connection.getConfirmedBlock(slot);
|
||||
if (block.transactions.length > 0) {
|
||||
const {signature, publicKey} =
|
||||
block.transactions[0].transaction.signatures[0];
|
||||
if (signature) {
|
||||
address = publicKey;
|
||||
expectedSignature = bs58.encode(signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// getSignaturesForAddress tests...
|
||||
await mockRpcResponse({
|
||||
method: 'getSignaturesForAddress',
|
||||
params: [address.toBase58(), {limit: 1}],
|
||||
value: [
|
||||
{
|
||||
signature: expectedSignature,
|
||||
slot,
|
||||
err: null,
|
||||
memo: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const signatures = await connection.getSignaturesForAddress(address, {
|
||||
limit: 1,
|
||||
});
|
||||
expect(signatures).to.have.length(1);
|
||||
if (mockServer) {
|
||||
expect(signatures[0].signature).to.eq(expectedSignature);
|
||||
expect(signatures[0].slot).to.eq(slot);
|
||||
expect(signatures[0].err).to.be.null;
|
||||
expect(signatures[0].memo).to.be.null;
|
||||
}
|
||||
});
|
||||
|
||||
it('get parsed confirmed transactions', async () => {
|
||||
await mockRpcResponse({
|
||||
method: 'getSlot',
|
||||
|
Reference in New Issue
Block a user