From 0a8be37b087470d9354f387d7c439cb0166eaf4d Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Fri, 15 Oct 2021 21:32:48 -0400 Subject: [PATCH] Fix issue when Solidity method collises with JavaScript prototype (#1432, #2054, #2120). --- packages/contracts/src.ts/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/contracts/src.ts/index.ts b/packages/contracts/src.ts/index.ts index c43dbfbf1d..60fe04c521 100644 --- a/packages/contracts/src.ts/index.ts +++ b/packages/contracts/src.ts/index.ts @@ -728,8 +728,8 @@ export class BaseContract { // are ambiguous { const name = fragment.name; - if (!uniqueNames[name]) { uniqueNames[name] = [ ]; } - uniqueNames[name].push(signature); + if (!uniqueNames[`%${ name }`]) { uniqueNames[`%${ name }`] = [ ]; } + uniqueNames[`%${ name }`].push(signature); } if ((this)[signature] == null) { @@ -757,11 +757,13 @@ export class BaseContract { }); Object.keys(uniqueNames).forEach((name) => { - // Ambiguous names to not get attached as bare names const signatures = uniqueNames[name]; if (signatures.length > 1) { return; } + // Strip off the leading "%" used for prototype protection + name = name.substring(1); + const signature = signatures[0]; // If overwriting a member property that is null, swallow the error