From 3793c4f2ec39aaee65e1ca3d7df3dad7307af881 Mon Sep 17 00:00:00 2001 From: Bobby Lat Date: Thu, 16 Jan 2025 18:25:18 +0800 Subject: [PATCH] fix: throw error if the param being passed to ctx.contract.create function is not detected to be a contract --- src/subcontexts/contract-context.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/subcontexts/contract-context.ts b/src/subcontexts/contract-context.ts index 61ba053..beba168 100644 --- a/src/subcontexts/contract-context.ts +++ b/src/subcontexts/contract-context.ts @@ -155,20 +155,20 @@ export class ContractContext { } private isArc4(type: IConstructor): boolean { - // TODO: uncomment the following line once version puya-ts 1.0.0 is released - // return (type as DeliberateAny as typeof BaseContract).isArc4 ?? false - const result = (type as DeliberateAny as typeof BaseContract).isArc4 if (result !== undefined && result !== null) { return result } + // TODO: uncomment the following line once version puya-ts 1.0.0 is released and delete the rest of the function + // throw new internal.errors.CodeError('Cannot create a contract for class as it does not extend Contract or BaseContract') + const proto = Object.getPrototypeOf(type) if (proto === BaseContract) { return false } else if (proto === Contract) { return true - } else if (proto === null) { - return false + } else if (proto === Object || proto === null) { + throw new internal.errors.CodeError('Cannot create a contract for class as it does not extend Contract or BaseContract') } return this.isArc4(proto) }