Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/contract/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ export class Contract implements ContractInterface {
this.parsingStrategy = options.parsingStrategy;
const parser = createAbiParser(options.abi, options.parsingStrategy);
this.abi = parser.getLegacyFormat();
this.address = options.address && options.address.toLowerCase();
this.address = options.address.toLowerCase();
assert(
typeof this.address === 'string' && this.address.length > 0,
Comment on lines +154 to +156
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the mentioned use case that would make the gist of this change undesirable, checking for the string type in the assert doesn't make sense since the code would throw a TypeError before the assert is reached.

'contract is not connected to an address'
);
this.providerOrAccount = options.providerOrAccount ?? defaultProvider;

// Optional params
Expand Down Expand Up @@ -217,7 +221,11 @@ export class Contract implements ContractInterface {

public attach(address: string, abi?: Abi): void {
// TODO: if changing address, probably changing abi also !? Also nonsense method as if you change abi and address, you need to create a new contract instance.
this.address = address;
this.address = address.toLowerCase();
assert(
typeof this.address === 'string' && this.address.length > 0,
'contract is not connected to an address'
);
if (abi) {
const parser = createAbiParser(abi, this.parsingStrategy);
this.abi = parser.getLegacyFormat();
Expand All @@ -228,6 +236,10 @@ export class Contract implements ContractInterface {
}

public async isDeployed(): Promise<this> {
assert(
typeof this.address === 'string' && this.address.length > 0,
'contract is not connected to an address'
);
try {
await this.providerOrAccount.getClassHashAt(this.address);
} catch (error) {
Expand All @@ -248,7 +260,10 @@ export class Contract implements ContractInterface {
blockIdentifier = undefined,
}: CallOptions = {}
): Promise<CallResult> {
assert(this.address !== null, 'contract is not connected to an address');
assert(
typeof this.address === 'string' && this.address.length > 0,
'contract is not connected to an address'
);

const calldata = getCompiledCalldata(args, () => {
if (parseRequest) {
Expand Down Expand Up @@ -300,7 +315,10 @@ export class Contract implements ContractInterface {
options: ExecuteOptions = {}
): Promise<SuccessfulTransactionReceiptResponseHelper | InvokeFunctionResponse> {
const { parseRequest = true, signature, waitForTransaction, ...RestInvokeOptions } = options;
assert(this.address !== null, 'contract is not connected to an address');
assert(
typeof this.address === 'string' && this.address.length > 0,
'contract is not connected to an address'
);

const calldata = getCompiledCalldata(args, () => {
if (parseRequest) {
Expand Down Expand Up @@ -352,7 +370,10 @@ export class Contract implements ContractInterface {
args: ArgsOrCalldata = [],
estimateDetails: UniversalDetails = {}
): Promise<EstimateFeeResponseOverhead> {
assert(this.address !== null, 'contract is not connected to an address');
assert(
typeof this.address === 'string' && this.address.length > 0,
'contract is not connected to an address'
);

if (!getCompiledCalldata(args, () => false)) {
this.callData.validate(ValidateType.INVOKE, method, args);
Expand Down
Loading