Revert "web3.js: deprecate getTotalSupply and getConfirmedSignaturesForAddress (#16534)" (#16594)

This reverts commit 59268b8629.
This commit is contained in:
Tyera Eulberg
2021-04-16 10:11:34 -06:00
committed by GitHub
parent d747614b27
commit 4ac17b1ee3
2 changed files with 35 additions and 259 deletions

View File

@ -492,15 +492,9 @@ describe('Connection', () => {
it('get total supply', async () => {
await mockRpcResponse({
method: 'getSupply',
method: 'getTotalSupply',
params: [],
value: {
total: 1000000,
circulating: 100000,
nonCirculating: 900000,
nonCirculatingAccounts: [new Account().publicKey.toBase58()],
},
withContext: true,
value: 1000000,
});
const count = await connection.getTotalSupply();
@ -603,50 +597,9 @@ describe('Connection', () => {
// getConfirmedSignaturesForAddress tests...
await mockRpcResponse({
method: 'getFirstAvailableBlock',
params: [],
value: 0,
});
const mockSignature =
'5SHZ9NwpnS9zYnauN7pnuborKf39zGMr11XpMC59VvRSeDJNcnYLecmdxXCVuBFPNQLdCBBjyZiNCL4KoHKr3tvz';
await mockRpcResponse({
method: 'getConfirmedBlock',
params: [slot, {transactionDetails: 'signatures', rewards: false}],
value: {
blockTime: 1614281964,
blockhash: 'H5nJ91eGag3B5ZSRHZ7zG5ZwXJ6ywCt2hyR8xCsV7xMo',
previousBlockhash: 'H5nJ91eGag3B5ZSRHZ7zG5ZwXJ6ywCt2hyR8xCsV7xMo',
parentSlot: 1,
signatures: [mockSignature],
},
});
await mockRpcResponse({
method: 'getSlot',
params: [],
value: 123,
});
await mockRpcResponse({
method: 'getConfirmedBlock',
params: [slot + 2, {transactionDetails: 'signatures', rewards: false}],
value: {
blockTime: 1614281964,
blockhash: 'H5nJ91eGag3B5ZSRHZ7zG5ZwXJ6ywCt2hyR8xCsV7xMo',
previousBlockhash: 'H5nJ91eGag3B5ZSRHZ7zG5ZwXJ6ywCt2hyR8xCsV7xMo',
parentSlot: 1,
signatures: [mockSignature],
},
});
await mockRpcResponse({
method: 'getConfirmedSignaturesForAddress2',
params: [address.toBase58(), {before: mockSignature}],
value: [
{
signature: expectedSignature,
slot,
err: null,
memo: null,
},
],
method: 'getConfirmedSignaturesForAddress',
params: [address.toBase58(), slot, slot + 1],
value: [expectedSignature],
});
const confirmedSignatures = await connection.getConfirmedSignaturesForAddress(
@ -658,17 +611,17 @@ describe('Connection', () => {
const badSlot = Number.MAX_SAFE_INTEGER - 1;
await mockRpcResponse({
method: 'getConfirmedBlock',
params: [badSlot - 1, {transactionDetails: 'signatures', rewards: false}],
error: {message: 'Block not available for slot ' + badSlot},
method: 'getConfirmedSignaturesForAddress',
params: [address.toBase58(), badSlot, badSlot + 1],
value: [],
});
expect(
connection.getConfirmedSignaturesForAddress(
address,
badSlot,
badSlot + 1,
),
).to.be.rejected;
const emptySignatures = await connection.getConfirmedSignaturesForAddress(
address,
badSlot,
badSlot + 1,
);
expect(emptySignatures).to.have.length(0);
// getConfirmedSignaturesForAddress2 tests...
await mockRpcResponse({
@ -1335,94 +1288,6 @@ describe('Connection', () => {
);
});
it('get confirmed block signatures', async () => {
await mockRpcResponse({
method: 'getSlot',
params: [],
value: 1,
});
while ((await connection.getSlot()) <= 0) {
continue;
}
await mockRpcResponse({
method: 'getConfirmedBlock',
params: [
0,
{
transactionDetails: 'signatures',
rewards: false,
},
],
value: {
blockTime: 1614281964,
blockhash: 'H5nJ91eGag3B5ZSRHZ7zG5ZwXJ6ywCt2hyR8xCsV7xMo',
previousBlockhash: 'H5nJ91eGag3B5ZSRHZ7zG5ZwXJ6ywCt2hyR8xCsV7xMo',
parentSlot: 0,
signatures: [],
},
});
// Block 0 never has any transactions in test validator
const block0 = await connection.getConfirmedBlockSignatures(0);
const blockhash0 = block0.blockhash;
expect(block0.signatures).to.have.length(0);
expect(blockhash0).not.to.be.null;
expect(block0.previousBlockhash).not.to.be.null;
expect(block0.parentSlot).to.eq(0);
expect(block0).to.not.have.property('rewards');
await mockRpcResponse({
method: 'getConfirmedBlock',
params: [
1,
{
transactionDetails: 'signatures',
rewards: false,
},
],
value: {
blockTime: 1614281964,
blockhash: '57zQNBZBEiHsCZFqsaY6h176ioXy5MsSLmcvHkEyaLGy',
previousBlockhash: 'H5nJ91eGag3B5ZSRHZ7zG5ZwXJ6ywCt2hyR8xCsV7xMo',
parentSlot: 0,
signatures: [
'w2Zeq8YkpyB463DttvfzARD7k9ZxGEwbsEw4boEK7jDp3pfoxZbTdLFSsEPhzXhpCcjGi2kHtHFobgX49MMhbWt',
'4oCEqwGrMdBeMxpzuWiukCYqSfV4DsSKXSiVVCh1iJ6pS772X7y219JZP3mgqBz5PhsvprpKyhzChjYc3VSBQXzG',
],
},
});
// Find a block that has a transaction, usually Block 1
let x = 1;
while (x < 10) {
const block1 = await connection.getConfirmedBlockSignatures(x);
if (block1.signatures.length >= 1) {
expect(block1.previousBlockhash).to.eq(blockhash0);
expect(block1.blockhash).not.to.be.null;
expect(block1.parentSlot).to.eq(0);
expect(block1.signatures[0]).not.to.be.null;
expect(block1).to.not.have.property('rewards');
break;
}
x++;
}
await mockRpcResponse({
method: 'getConfirmedBlock',
params: [Number.MAX_SAFE_INTEGER],
error: {
message: `Block not available for slot ${Number.MAX_SAFE_INTEGER}`,
},
});
await expect(
connection.getConfirmedBlockSignatures(Number.MAX_SAFE_INTEGER),
).to.be.rejectedWith(
`Block not available for slot ${Number.MAX_SAFE_INTEGER}`,
);
});
it('get recent blockhash', async () => {
const commitments: Commitment[] = ['processed', 'confirmed', 'finalized'];
for (const commitment of commitments) {