You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 29, 2020. It is now read-only.
The current API is not ideal and has several problems including:
Function names from abi can override doppelganger properties and methods e.g. deploy,
Overloaded methods are not supported on the Doppelganger object,
It is possible to cause exceptions because the user called Doppelganger methods in an incorrect order (calling .returns(...) before deploy(),
Setup requires calling multiple methods.
To address some of those issues the following API can be used:
constabi=['function transfer(address,uint256) public returns(bool)','function foo() public returns(uint256,string)','function bar(uint256 x) public pure returns (uint256)','function bar(bool x) public pure returns (bool)',];asyncfunctionexample(){constdoppelganger=newDoppelganger(abi);const{ address }=awaitdoppelganger.deploy();awaitdoppelganger.methods.transfer.returns(true);awaitdoppelganger.methods.transfer.returns(42,'hello');// support for overloaded names. Requires identifierawaitdoppelganger.methods['bar#0423a132'].returns(1337);}
The changes are as follows:
deploy returns the contract instance, making it easy to get the address and the contract safely,
all of the abi methods names now reside in the doppelganger.methods object,
a special syntax name#hex is used for overloaded methods
However I believe some further improvements can be made if we allow some bigger changes. Let's look at the following example:
constabi=['function transfer(address,uint256) public returns(bool)','function foo() public returns(uint256,string)','function bar(uint256 x) public pure returns (uint256)','function bar(bool x) public pure returns (bool)',];asyncfunctionexample(){// create initially. Deploys and sets up methodsconstdoppelganger=awaitDoppelganger.from(abi,{transfer: true,foo: [42,'hello'],'bar#0423a132': 1337,// support for overloaded names. Requires identifier});// access membersconstusedAbi=doppelganger.abi;constcontract=doppelganger.contract;constaddress=doppelganger.address;// change something laterawaitdoppelganger.mockReturn('transfer',false);awaitdoppelganger.mockReturn('foo',[21,':37']);}
This approach addresses all of the pain points listed at the start of this issue, by deploying the contract in the constructor (that is no longer strictly class based).
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The current API is not ideal and has several problems including:
deploy
,.returns(...)
beforedeploy()
,To address some of those issues the following API can be used:
The changes are as follows:
deploy
returns the contract instance, making it easy to get the address and the contract safely,doppelganger.methods
object,name#hex
is used for overloaded methodsHowever I believe some further improvements can be made if we allow some bigger changes. Let's look at the following example:
This approach addresses all of the pain points listed at the start of this issue, by deploying the contract in the constructor (that is no longer strictly class based).
The text was updated successfully, but these errors were encountered: