diff --git a/package.json b/package.json index 4f5b530a..bf9be5e0 100644 --- a/package.json +++ b/package.json @@ -124,7 +124,7 @@ "_dist-stats": "gzip -k9f -S '.gz' ./dist/quais.min.js && gzip -k9f -S '.gz' ./dist/quais.umd.min.js && gzip -k9f -S '.gz' ./dist/wordlists-extra.min.js && du -hs ./dist/*.gz && echo '' && du -hs ./dist/*.js", "auto-build": "npm run build -- -w", "lint": "eslint src/**/*.ts --fix", - "build": "tsc --project tsconfig.esm.json && cp ./misc/basedirs/lib.esm/package.json ./lib/esm", + "build": "tsc --project tsconfig.esm.json && cp ./misc/basedirs/lib/esm/package.json ./lib/esm", "build-all": "npm run build && npm run build-commonjs", "build-clean": "npm run clean && npm run build && npm run build-all && npm run _build-dist && npm run _dist-stats", "build-commonjs": "tsc --project tsconfig.commonjs.json", diff --git a/src/_tests/test-address.ts b/src/_tests/test-address.ts index 7b75d93e..bf6ed4d5 100644 --- a/src/_tests/test-address.ts +++ b/src/_tests/test-address.ts @@ -53,7 +53,7 @@ describe('computes checksum address', function () { function (error: any) { return ( error.code === 'INVALID_ARGUMENT' && - error.message.match(/^bad address checksum/) && + error.message.match(/^invalid address checksum/) && error.argument === 'address' && error.value === value ); @@ -84,6 +84,7 @@ describe('computes ICAP address', function () { } }); +// TODO: make getCreateAddress match go-quai's implementation to get this to pass describe('computes create address', function () { const tests = loadTests('create'); for (const { sender, creates } of tests) { diff --git a/src/_tests/test-contract-integ.ts b/src/_tests/test-contract-integ.ts index fc95694e..5147d1eb 100644 --- a/src/_tests/test-contract-integ.ts +++ b/src/_tests/test-contract-integ.ts @@ -13,7 +13,7 @@ interface ContractAbi { transfer: quais.BaseContractMethod<[quais.AddressLike, bigint], [boolean], quais.ContractTransactionResponse>; } -describe("Tests contract integration", function() { +describe('Tests contract integration', function () { const provider = new quais.JsonRpcProvider(process.env.CYPRUS1URL); const wallet = new quais.Wallet(process.env.CYPRUS1PK || '', provider); const abi = QRC20.abi; @@ -27,17 +27,19 @@ describe("Tests contract integration", function() { let address: string; before(async function () { - this.timeout(100000); + this.timeout(200000); const factory = new quais.ContractFactory(abi, bytecode, wallet as quais.ContractRunner); contract = (await factory.deploy(constructorArgs.name, constructorArgs.symbol, constructorArgs.totalSupply, { gasLimit: 5000000, + maxFeePerGas: quais.parseUnits('10', 'gwei'), + maxPriorityFeePerGas: quais.parseUnits('3', 'gwei'), })) as Contract; address = await contract.getAddress(); console.log('Contract deployed to:', address); let tries = 0; - const POLLING_TRIES = 10; // define POLLING_TRIES if not defined elsewhere + const POLLING_TRIES = 20; // define POLLING_TRIES if not defined elsewhere let deployed = false; let code = await provider.getCode(address); while (tries < POLLING_TRIES && !deployed) { diff --git a/src/_tests/test-contract.ts b/src/_tests/test-contract.ts index 2ee87fb6..b0b6b93f 100644 --- a/src/_tests/test-contract.ts +++ b/src/_tests/test-contract.ts @@ -10,15 +10,15 @@ import { stall } from './utils.js'; setupProviders(); -describe("Test Contract", function() { - const provider = new quais.JsonRpcProvider(process.env.CYPRUS1URL) +describe('Test Contract', function () { + const provider = new quais.JsonRpcProvider(process.env.CYPRUS1URL); const wallet = new quais.Wallet(process.env.CYPRUS1PK || '', provider); const abi = TestContract.abi; const bytecode = TestContract.bytecode; let contract: Contract; let addr: string; before(async function () { - this.timeout(60000); + this.timeout(100000); await stall(10000); const factory = new ContractFactory(abi, bytecode, wallet as ContractRunner); contract = (await factory.deploy({ @@ -28,7 +28,7 @@ describe("Test Contract", function() { })) as Contract; addr = await contract.getAddress(); console.log('Contract deployed to: ', addr); - await stall(30000); + await stall(50000); }); it('tests contract calls', async function () { @@ -359,8 +359,8 @@ describe('Test Typed Contract Interaction', function () { }, ]; - const abi = TypedContract.abi - const provider = new quais.JsonRpcProvider(process.env.CYPRUS1URL) + const abi = TypedContract.abi; + const provider = new quais.JsonRpcProvider(process.env.CYPRUS1URL); const wallet = new quais.Wallet(process.env.CYPRUS1PK || '', provider); const bytecode = TypedContract.bytecode; let contract: Contract; @@ -375,7 +375,7 @@ describe('Test Typed Contract Interaction', function () { })) as Contract; addr = await contract.getAddress(); console.log('Contract deployed to: ', addr); - await stall(50000); + await stall(100000); }); for (const { types, valueFunc } of tests) { @@ -423,7 +423,7 @@ describe('Test Contract Fallback', function () { const tests: Array = [ { name: 'none', - address: '0x0ccdace3d8353fed9b87a2d63c40452923ccdae5', + address: '0x0CcdacE3D8353FeD9B87a2D63c40452923CcDAE5', abi: [], sendNone: { error: 'no fallback' }, sendData: { error: 'no fallback' }, @@ -432,7 +432,7 @@ describe('Test Contract Fallback', function () { }, { name: 'non-payable fallback', - address: '0x3f10193f79a639b11ec9d2ab42a25a4a905a8870', + address: '0x3F10193F79A639b11eC9d2AB42A25A4a905a8870', abi: ['fallback()'], sendNone: { data: '0x' }, sendData: { data: '0x1234' }, @@ -441,7 +441,7 @@ describe('Test Contract Fallback', function () { }, { name: 'payable fallback', - address: '0xe2de6b97c5eb9fee8a47ca6c0fa642331e0b6330', + address: '0xe2de6B97C5eB9Fee8a47ca6c0fa642331E0B6330', abi: ['fallback() payable'], sendNone: { data: '0x' }, sendData: { data: '0x1234' }, @@ -450,7 +450,7 @@ describe('Test Contract Fallback', function () { }, { name: 'receive-only', - address: '0xf8f2afbbe37f6a4520e4db7f99495655aa31229b', + address: '0xF8F2AfbBE37F6a4520e4Db7F99495655aa31229b', abi: ['receive()'], sendNone: { data: '0x' }, sendData: { error: 'overrides.data' }, @@ -459,7 +459,7 @@ describe('Test Contract Fallback', function () { }, { name: 'receive and payable fallback', - address: '0x7d97ca5d9dea1cd0364f1d493252006a3c4e18a0', + address: '0x7d97CA5D9deA1Cd0364f1D493252006A3c4e18a0', abi: ['fallback() payable', 'receive()'], sendNone: { data: '0x' }, sendData: { data: '0x1234' }, @@ -468,7 +468,7 @@ describe('Test Contract Fallback', function () { }, { name: 'receive and non-payable fallback', - address: '0x5b59d934f0d22b15e73b5d6b9ae83486b70df67e', + address: '0x5B59D934f0D22b15e73b5d6b9Ae83486B70dF67e', abi: ['fallback()', 'receive()'], sendNone: { data: '0x' }, sendData: { data: '0x' }, diff --git a/src/address/index.ts b/src/address/index.ts index a5000c1a..8025f07d 100644 --- a/src/address/index.ts +++ b/src/address/index.ts @@ -31,7 +31,7 @@ export interface Addressable { */ export type AddressLike = string | Promise | Addressable; -export { getAddress, computeAddress, recoverAddress } from './address.js'; +export { getAddress, computeAddress, recoverAddress, formatMixedCaseChecksumAddress } from './address.js'; export { getCreateAddress, getCreate2Address } from './contract-address.js'; diff --git a/src/contract/contract.ts b/src/contract/contract.ts index 38760424..ce1df835 100644 --- a/src/contract/contract.ts +++ b/src/contract/contract.ts @@ -336,10 +336,6 @@ function buildWrappedMethod< data: contract.interface.encodeFunctionData(fragment, resolvedArgs), }), ); - - // if (overrides.from) { - // overrides.from = await resolveAddress(overrides.from, getResolver(contract.runner)); - // } } if (fragment.inputs.length !== args.length) { @@ -350,7 +346,7 @@ function buildWrappedMethod< return await resolveProperties({ to: contract.getAddress(), - from: args.pop().from, + from: args.pop()?.from ?? '0x0000000000000000000000000000000000000000', data: contract.interface.encodeFunctionData(fragment, resolvedArgs), }); }; @@ -368,8 +364,17 @@ function buildWrappedMethod< assert(canSend(runner), 'contract runner does not support sending transactions', 'UNSUPPORTED_OPERATION', { operation: 'sendTransaction', }); + const pop = await populateTransaction(...args); + if ( + runner && + 'address' in runner && + typeof runner.address == 'string' && + pop.from === '0x0000000000000000000000000000000000000000' + ) { + pop.from = runner.address; + } - const tx = (await runner.sendTransaction(await populateTransaction(...args))) as QuaiTransactionResponse; + const tx = (await runner.sendTransaction(await pop)) as QuaiTransactionResponse; const provider = getProvider(contract.runner); // @TODO: the provider can be null; make a custom dummy provider that will throw a // meaningful error @@ -390,8 +395,15 @@ function buildWrappedMethod< assert(canCall(runner), 'contract runner does not support calling', 'UNSUPPORTED_OPERATION', { operation: 'call', }); - const tx = await populateTransaction(...args); + if ( + runner && + 'address' in runner && + typeof runner.address == 'string' && + tx.from === '0x0000000000000000000000000000000000000000' + ) { + tx.from = runner.address; + } let result = '0x'; try { diff --git a/src/providers/format.ts b/src/providers/format.ts index b4b8b4b4..92a9f72e 100644 --- a/src/providers/format.ts +++ b/src/providers/format.ts @@ -307,7 +307,7 @@ export function formatTransactionResponse(value: any): TransactionResponseParams let result: TransactionResponseParams; - if (transactionType === 0x1) { + if (transactionType === 0x0) { // QuaiTransactionResponseParams result = object( { @@ -341,7 +341,7 @@ export function formatTransactionResponse(value: any): TransactionResponseParams )(value) as QuaiTransactionResponseParams; // Add an access list to supported transaction types - if ((value.type === 1 || value.type === 2) && value.accessList == null) { + if ((value.type === 0 || value.type === 2) && value.accessList == null) { result.accessList = []; } diff --git a/src/quais.ts b/src/quais.ts index 275d1094..17f98c43 100644 --- a/src/quais.ts +++ b/src/quais.ts @@ -36,6 +36,7 @@ export { isAddress, resolveAddress, validateAddress, + formatMixedCaseChecksumAddress, } from './address/index.js'; //CONSTANTS @@ -80,7 +81,7 @@ export { lock, Signature, SigningKey, - musigCrypto + musigCrypto, } from './crypto/index.js'; // HASH @@ -122,9 +123,11 @@ export { AbstractSigner, VoidSigner } from './signers/index.js'; // TRANSACTION export { accessListify, - AbstractTransaction, FewestCoinSelector, - QiTransaction, QuaiTransaction -} from "./transaction/index.js"; + AbstractTransaction, + FewestCoinSelector, + QiTransaction, + QuaiTransaction, +} from './transaction/index.js'; // UTILS export {