fix: Rename lastId to blockhash
This commit is contained in:
@ -8,7 +8,7 @@ import {
|
||||
sendAndConfirmTransaction,
|
||||
} from '../src';
|
||||
import {mockRpc, mockRpcEnabled} from './__mocks__/node-fetch';
|
||||
import {mockGetLastId} from './mockrpc/getlastid';
|
||||
import {mockGetRecentBlockhash} from './mockrpc/get-recent-blockhash';
|
||||
import {url} from './url';
|
||||
import {sleep} from '../src/util/sleep';
|
||||
|
||||
@ -117,10 +117,10 @@ test('get transaction count', async () => {
|
||||
test('get last Id', async () => {
|
||||
const connection = new Connection(url);
|
||||
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
|
||||
const lastId = await connection.getLastId();
|
||||
expect(lastId.length).toBeGreaterThanOrEqual(43);
|
||||
const recentBlockhash = await connection.getRecentBlockhash();
|
||||
expect(recentBlockhash.length).toBeGreaterThanOrEqual(43);
|
||||
});
|
||||
|
||||
test('request airdrop', async () => {
|
||||
@ -282,7 +282,7 @@ test('transaction', async () => {
|
||||
await connection.requestAirdrop(accountTo.publicKey, 21);
|
||||
expect(await connection.getBalance(accountTo.publicKey)).toBe(21);
|
||||
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockRpc.push([
|
||||
url,
|
||||
{
|
||||
|
@ -4,18 +4,18 @@ import {Account} from '../../src';
|
||||
import {url} from '../url';
|
||||
import {mockRpc} from '../__mocks__/node-fetch';
|
||||
|
||||
export function mockGetLastId() {
|
||||
const lastId = new Account();
|
||||
export function mockGetRecentBlockhash() {
|
||||
const recentBlockhash = new Account();
|
||||
|
||||
mockRpc.push([
|
||||
url,
|
||||
{
|
||||
method: 'getLastId',
|
||||
method: 'getRecentBlockhash',
|
||||
params: [],
|
||||
},
|
||||
{
|
||||
error: null,
|
||||
result: lastId.publicKey.toBase58(),
|
||||
result: recentBlockhash.publicKey.toBase58(),
|
||||
},
|
||||
]);
|
||||
}
|
@ -5,7 +5,7 @@ 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';
|
||||
import {mockGetRecentBlockhash} from './mockrpc/get-recent-blockhash';
|
||||
import {sleep} from '../src/util/sleep';
|
||||
|
||||
if (!mockRpcEnabled) {
|
||||
@ -48,29 +48,29 @@ let initialOwnerTokenAccount: PublicKey;
|
||||
|
||||
test('create new token', async () => {
|
||||
const connection = new Connection(url);
|
||||
connection._disableLastIdCaching = mockRpcEnabled;
|
||||
connection._disableBlockhashCaching = mockRpcEnabled;
|
||||
|
||||
initialOwner = await newAccountWithTokens(connection, 1024);
|
||||
|
||||
{
|
||||
// mock SystemProgram.createAccount transaction for Token.createNewToken()
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus();
|
||||
|
||||
// mock Token.newAccount() transaction
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus('SignatureNotFound');
|
||||
mockGetSignatureStatus();
|
||||
|
||||
// mock SystemProgram.createAccount transaction for Token.createNewToken()
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus();
|
||||
|
||||
// mock Token.createNewToken() transaction
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus('SignatureNotFound');
|
||||
mockGetSignatureStatus();
|
||||
@ -228,17 +228,17 @@ test('create new token', async () => {
|
||||
|
||||
test('create new token account', async () => {
|
||||
const connection = new Connection(url);
|
||||
connection._disableLastIdCaching = mockRpcEnabled;
|
||||
connection._disableBlockhashCaching = mockRpcEnabled;
|
||||
const destOwner = await newAccountWithTokens(connection);
|
||||
|
||||
{
|
||||
// mock SystemProgram.createAccount transaction for Token.newAccount()
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus();
|
||||
|
||||
// mock Token.newAccount() transaction
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus();
|
||||
}
|
||||
@ -287,17 +287,17 @@ test('create new token account', async () => {
|
||||
|
||||
test('transfer', async () => {
|
||||
const connection = new Connection(url);
|
||||
connection._disableLastIdCaching = mockRpcEnabled;
|
||||
connection._disableBlockhashCaching = mockRpcEnabled;
|
||||
const destOwner = await newAccountWithTokens(connection);
|
||||
|
||||
{
|
||||
// mock SystemProgram.createAccount transaction for Token.newAccount()
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus();
|
||||
|
||||
// mock Token.newAccount() transaction
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus();
|
||||
}
|
||||
@ -337,7 +337,7 @@ test('transfer', async () => {
|
||||
]);
|
||||
|
||||
// mock Token.transfer() transaction
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus();
|
||||
}
|
||||
@ -385,17 +385,17 @@ test('transfer', async () => {
|
||||
|
||||
test('approve/revoke', async () => {
|
||||
const connection = new Connection(url);
|
||||
connection._disableLastIdCaching = mockRpcEnabled;
|
||||
connection._disableBlockhashCaching = mockRpcEnabled;
|
||||
const delegateOwner = await newAccountWithTokens(connection);
|
||||
|
||||
{
|
||||
// mock SystemProgram.createAccount transaction for Token.newAccount()
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus();
|
||||
|
||||
// mock Token.newAccount() transaction
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus();
|
||||
}
|
||||
@ -406,7 +406,7 @@ test('approve/revoke', async () => {
|
||||
|
||||
{
|
||||
// mock Token.approve() transaction
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus();
|
||||
}
|
||||
@ -474,7 +474,7 @@ test('approve/revoke', async () => {
|
||||
|
||||
{
|
||||
// mock Token.revoke() transaction
|
||||
mockGetLastId();
|
||||
mockGetRecentBlockhash();
|
||||
mockSendTransaction();
|
||||
mockGetSignatureStatus();
|
||||
}
|
||||
@ -542,7 +542,7 @@ test('invalid approve', async () => {
|
||||
}
|
||||
|
||||
const connection = new Connection(url);
|
||||
connection._disableLastIdCaching = mockRpcEnabled;
|
||||
connection._disableBlockhashCaching = mockRpcEnabled;
|
||||
const owner = await newAccountWithTokens(connection);
|
||||
|
||||
const account1 = await testToken.newAccount(owner);
|
||||
@ -567,7 +567,7 @@ test('fail on approve overspend', async () => {
|
||||
}
|
||||
|
||||
const connection = new Connection(url);
|
||||
connection._disableLastIdCaching = mockRpcEnabled;
|
||||
connection._disableBlockhashCaching = mockRpcEnabled;
|
||||
const owner = await newAccountWithTokens(connection);
|
||||
|
||||
const account1 = await testToken.newAccount(owner);
|
||||
@ -611,7 +611,7 @@ test('set owner', async () => {
|
||||
}
|
||||
|
||||
const connection = new Connection(url);
|
||||
connection._disableLastIdCaching = mockRpcEnabled;
|
||||
connection._disableBlockhashCaching = mockRpcEnabled;
|
||||
const owner = await newAccountWithTokens(connection);
|
||||
const newOwner = await newAccountWithTokens(connection);
|
||||
|
||||
|
@ -7,13 +7,13 @@ import {SystemProgram} from '../src/system-program';
|
||||
test('signPartial', () => {
|
||||
const account1 = new Account();
|
||||
const account2 = new Account();
|
||||
const lastId = account1.publicKey.toBase58(); // Fake lastId
|
||||
const recentBlockhash = account1.publicKey.toBase58(); // Fake recentBlockhash
|
||||
const move = SystemProgram.move(account1.publicKey, account2.publicKey, 123);
|
||||
|
||||
const transaction = new Transaction({lastId}).add(move);
|
||||
const transaction = new Transaction({recentBlockhash}).add(move);
|
||||
transaction.sign(account1, account2);
|
||||
|
||||
const partialTransaction = new Transaction({lastId}).add(move);
|
||||
const partialTransaction = new Transaction({recentBlockhash}).add(move);
|
||||
partialTransaction.signPartial(account1, account2.publicKey);
|
||||
expect(partialTransaction.signatures[1].signature).toBeNull();
|
||||
partialTransaction.addSigner(account2);
|
||||
@ -24,15 +24,15 @@ test('signPartial', () => {
|
||||
test('transfer signatures', () => {
|
||||
const account1 = new Account();
|
||||
const account2 = new Account();
|
||||
const lastId = account1.publicKey.toBase58(); // Fake lastId
|
||||
const recentBlockhash = account1.publicKey.toBase58(); // Fake recentBlockhash
|
||||
const move1 = SystemProgram.move(account1.publicKey, account2.publicKey, 123);
|
||||
const move2 = SystemProgram.move(account2.publicKey, account1.publicKey, 123);
|
||||
|
||||
const orgTransaction = new Transaction({lastId}).add(move1, move2);
|
||||
const orgTransaction = new Transaction({recentBlockhash}).add(move1, move2);
|
||||
orgTransaction.sign(account1, account2);
|
||||
|
||||
const newTransaction = new Transaction({
|
||||
lastId: orgTransaction.lastId,
|
||||
recentBlockhash: orgTransaction.recentBlockhash,
|
||||
fee: orgTransaction.fee,
|
||||
signatures: orgTransaction.signatures,
|
||||
}).add(move1, move2);
|
||||
@ -41,13 +41,13 @@ test('transfer signatures', () => {
|
||||
});
|
||||
|
||||
test('parse wire format and serialize', () => {
|
||||
const lastId = 'EETubP5AKHgjPAhzPAFcb8BAY1hMH639CWCFTqi3hq1k'; // Arbitrary known lastId
|
||||
const recentBlockhash = 'EETubP5AKHgjPAhzPAFcb8BAY1hMH639CWCFTqi3hq1k'; // Arbitrary known recentBlockhash
|
||||
const sender = new Account(Buffer.alloc(64, 8)); // Arbitrary known account
|
||||
const recipient = new PublicKey(
|
||||
'J3dxNj7nDRRqRRXuEMynDG57DkZK4jYRuv3Garmb1i99',
|
||||
); // Arbitrary known public key
|
||||
const move = SystemProgram.move(sender.publicKey, recipient, 49);
|
||||
const expectedTransaction = new Transaction({lastId}).add(move);
|
||||
const expectedTransaction = new Transaction({recentBlockhash}).add(move);
|
||||
expectedTransaction.sign(sender);
|
||||
|
||||
const wireTransaction = Buffer.from([
|
||||
|
Reference in New Issue
Block a user