Skip to content

Commit

Permalink
Adds more documentation for contract proxying
Browse files Browse the repository at this point in the history
  • Loading branch information
crystalin committed Nov 12, 2024
1 parent 76e746f commit 767cc80
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/contracts/src/ProxyForContractsDemo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ interface IProxy{
) external payable;
}

// This contract adds Alith (0xf24....) as proxy to itself when it gets deployed.
// The purpose is to trigger a proxy creation BEFORE the contract code is stored.
// It bypasses the restriction of "no proxy for smart contract" but cannot be exploited
// because runtimes block the execution of a proxy if the proxied account contains code
// see https://github.com/moonbeam-foundation/moonbeam/pull/2533/files#diff-95857a497fb7c3739b385c704d94c0f41293c05703b539cb139093f78e0a4cfbR1122
contract ProxyForContractsDemo {

address immutable PROXY_ADDRESS = 0x000000000000000000000000000000000000080b;
Expand Down
12 changes: 12 additions & 0 deletions test/suites/dev/moonbase/test-proxy/test-proxy-for-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describeSuite({
contractAddress = deployedAddr;
});

// See ProxyForContractsDemo.sol for more explanation
it({
id: `T01`,
title: `Proxy Call to Smart Contract account should fail`,
Expand All @@ -37,5 +38,16 @@ describeSuite({
).rejects.toThrow("Invalid Transaction: Transaction call is not expected");
},
});

it({
id: `T02`,
title: `Adding a proxy to an existing contract should succeed`,
test: async function () {
const { result } = await context.createBlock(
context.polkadotJs().tx.proxy.addProxy(contractAddress, "Any", 0)
)
expect(result?.successful).to.be.true;
},
});
},
});

0 comments on commit 767cc80

Please sign in to comment.