Skip to content

Commit

Permalink
Fix usage of wrong ethereum object for ethereum endowment (#1064)
Browse files Browse the repository at this point in the history
* Fix usage of wrong ethereum object for ethereum endowment

* Add test
  • Loading branch information
FrederikBolding committed Dec 13, 2022
1 parent f39d07e commit fcd2e9c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Expand Up @@ -64,6 +64,16 @@ describe('Endowment utils', () => {
expect(endowments.mockEndowment).toBeDefined();
});

it('handles special case for ethereum endowment', () => {
Object.assign(globalThis, { ethereum: {} });
const { endowments } = createEndowments(
mockSnapAPI as any,
mockEthereum as any,
['ethereum'],
);
expect(endowments.ethereum).toBe(mockEthereum);
});

it('handles factory endowments', () => {
const { endowments } = createEndowments(
mockSnapAPI as any,
Expand Down
Expand Up @@ -84,6 +84,9 @@ export function createEndowments(
}

allEndowments[endowmentName] = attenuatedEndowments[endowmentName];
} else if (endowmentName === 'ethereum') {
// Special case for adding the EIP-1193 provider.
allEndowments[endowmentName] = ethereum;
} else if (endowmentName in rootRealmGlobal) {
// If the endowment doesn't have a factory, just use whatever is on the
// global object.
Expand All @@ -94,9 +97,6 @@ export function createEndowments(
typeof globalValue === 'function' && !isConstructor(globalValue)
? globalValue.bind(rootRealmGlobal)
: globalValue;
} else if (endowmentName === 'ethereum') {
// Special case for adding the EIP-1193 provider.
allEndowments[endowmentName] = ethereum;
} else {
// If we get to this point, we've been passed an endowment that doesn't
// exist in our current environment.
Expand Down

0 comments on commit fcd2e9c

Please sign in to comment.