@moonsong-labs/moonwall-util
Version:
Testing framework for the Moon family of projects
104 lines (101 loc) • 3.72 kB
TypeScript
import { Web3, JsonRpcResponse } from 'web3';
import { AccessListish } from 'ethers';
import { Debugger } from 'debug';
/**
* @name TransactionOptions
* @description Ethereum Transaction options
* @param from: From address
* @param to: To address
* @param privateKey: Private key of the account to sign the transaction
* @param nonce: Nonce of the transaction
* @param gas: Gas limit of the transaction
* @param gasPrice: Gas price of the transaction
* @param maxFeePerGas: Max fee per gas of the transaction
* @param maxPriorityFeePerGas: Max priority fee per gas of the transaction
* @param value: Value of the transaction
* @param data: Data of the transaction
* @param accessList: Access list of the transaction
*/
interface TransactionOptions {
from?: string;
to?: string;
privateKey?: string;
nonce?: number | BigInt;
gas?: string | number | BigInt;
gasPrice?: string | number | BigInt;
maxFeePerGas?: string | number | BigInt;
maxPriorityFeePerGas?: string | number | BigInt;
value?: string | number;
data?: string;
accessList?: AccessListish;
}
/**
* @name EthTester
* @description Class to generate Ethereum transactions for testing purposes
*/
declare class EthTester {
/**
* @name defaultType: Default type of Ethereum transaction
*/
private defaultType;
/**
* @name defaultType: Default account to sign Ethereum transactions (usually sudo account)
*/
private defaultAccount;
/**
* @name logger: Logger to use
*/
private logger;
/**
* @name web3: Web3 instance
*/
web3: Web3;
/**
* @name constructor
* @param web3: Web3 instance
* @param privateKey: Private key of the default account
* @param logger: Logger to use
* @param type: Default type of Ethereum transaction
* @returns Web3Tester instance
* @description Creates a new Web3Tester instance
* @example
* const web3 = new Web3("http://localhost:9944");
* const web3Tester = new Web3Tester(web3, alith.privateKey, logger, "EIP1559");
* const rawTransaction = await web3Tester.genSignedTransfer({
* to: baltathar.address,
* value: web3.utils.toWei("1", "ether"),
* });
*/
constructor(web3: Web3, privateKey: string, logger: Debugger, type?: "Legacy" | "EIP2930" | "EIP1559");
/**
* @name genSignedTransaction
* @param options: Transaction options
* @param txType: Type of Ethereum transaction
* @returns Signed transaction
* @description Generates a signed Ethereum transaction
* @example
* const rawTransaction = await web3Tester.genSignedTransaction({
* to: baltathar.address,
* to: authorMapping.address,
* data: authorMapping.encodeFunctionData("setKeys", [keys]),
* });
*/
genSignedTransaction: (options: TransactionOptions, txType?: "Legacy" | "EIP2930" | "EIP1559") => Promise<string>;
/**
* @name genSignedTransfer
* @param to Address of the recipient
* @param value Amount of Wei to send
* @param options Transaction options
* @description Generates a signed Ethereum transactiosn
* @returns Signed transaction
*/
genSignedTransfer: (to: string, value: number | string | BigInt, options: TransactionOptions) => Promise<string>;
/**
* @name sendSignedTransaction
* @description Sends a signed transaction, without waiting for it to be produced.
* @param rawTransaction Signed transaction
* @returns Transaction JSON RPC response
*/
sendSignedTransaction: (rawTransaction: string | PromiseLike<string>) => Promise<JsonRpcResponse>;
}
export { EthTester, TransactionOptions };