Skip to content

Commit

Permalink
clean bugs found from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlincecum committed Jun 10, 2024
1 parent 1090a22 commit 32d0e4e
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/_tests/test-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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<TestCaseCreate>('create');
for (const { sender, creates } of tests) {
Expand Down
8 changes: 5 additions & 3 deletions src/_tests/test-contract-integ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
26 changes: 13 additions & 13 deletions src/_tests/test-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 () {
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -423,7 +423,7 @@ describe('Test Contract Fallback', function () {
const tests: Array<TestContractFallback> = [
{
name: 'none',
address: '0x0ccdace3d8353fed9b87a2d63c40452923ccdae5',
address: '0x0CcdacE3D8353FeD9B87a2D63c40452923CcDAE5',
abi: [],
sendNone: { error: 'no fallback' },
sendData: { error: 'no fallback' },
Expand All @@ -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' },
Expand All @@ -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' },
Expand All @@ -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' },
Expand All @@ -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' },
Expand All @@ -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' },
Expand Down
2 changes: 1 addition & 1 deletion src/address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface Addressable {
*/
export type AddressLike = string | Promise<string> | Addressable;

export { getAddress, computeAddress, recoverAddress } from './address.js';
export { getAddress, computeAddress, recoverAddress, formatMixedCaseChecksumAddress } from './address.js';

export { getCreateAddress, getCreate2Address } from './contract-address.js';

Expand Down
26 changes: 19 additions & 7 deletions src/contract/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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),
});
};
Expand All @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/providers/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export function formatTransactionResponse(value: any): TransactionResponseParams

let result: TransactionResponseParams;

if (transactionType === 0x1) {
if (transactionType === 0x0) {
// QuaiTransactionResponseParams
result = object(
{
Expand Down Expand Up @@ -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 = [];
}

Expand Down
11 changes: 7 additions & 4 deletions src/quais.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export {
isAddress,
resolveAddress,
validateAddress,
formatMixedCaseChecksumAddress,
} from './address/index.js';

//CONSTANTS
Expand Down Expand Up @@ -80,7 +81,7 @@ export {
lock,
Signature,
SigningKey,
musigCrypto
musigCrypto,
} from './crypto/index.js';

// HASH
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 32d0e4e

Please sign in to comment.