modified mock.sol and readme

This commit is contained in:
Sowmay Jain 2020-05-02 22:18:39 +10:00
parent 379ac709b8
commit 52fbe1baad
2 changed files with 17 additions and 5 deletions

View File

@ -14,10 +14,11 @@ Connectors are standardized modules that let Smart Account interact with various
- The contracts should not have `selfdestruct()`. - The contracts should not have `selfdestruct()`.
- The contracts should not have `delegatecall()`. - The contracts should not have `delegatecall()`.
- Use `uint(-1)` for maximum amount everywhere ([example](/)). - Use `uint(-1)` for maximum amount everywhere.
- Import `contracts/common` files ([example](/)). - Import files from common directory.
- Add `getId` & `setId`, two additional parameter for external public facing functions ([example](/)). - If needed, add `getId` & `setId`, two additional parameter for external public facing functions to fetch or store values.
- Use `getUint()` or `setUint()` functions to fetch or store values ([example](/)). - Use `getUint()` or `setUint()` functions to fetch or store values.
- Call `emitEvent()` after every external public facing functions to follow a common event standard for better analytics.
## Support ## Support

View File

@ -1,5 +1,6 @@
pragma solidity ^0.6.0; pragma solidity ^0.6.0;
// import files from common directory
import { DSMath } from "../common/math.sol"; import { DSMath } from "../common/math.sol";
import { Stores } from "../common/stores.sol"; import { Stores } from "../common/stores.sol";
@ -7,9 +8,19 @@ contract MockProtocol is Stores, DSMath {
event LogMock(uint mockOne, uint mockTwo, uint getId, uint setId); event LogMock(uint mockOne, uint mockTwo, uint getId, uint setId);
// added two additional parameter (getId & setId) for external public facing functions
function mockFunction(uint mockNumber, uint getId, uint setId) external payable { function mockFunction(uint mockNumber, uint getId, uint setId) external payable {
uint mockBalance = mockNumber == uint(-1) ? address(this).balance : mockNumber;
// fetch value of specific id
uint mockBalance = getUint(getId, mockNumber);
// uses uint(-1)
mockBalance = mockBalance == uint(-1) ? address(this).balance : mockNumber;
// store new value for specific id
setUint(setId, mockNumber);
// common event standard
emit LogMock(mockNumber, mockBalance, getId, setId); emit LogMock(mockNumber, mockBalance, getId, setId);
bytes32 eventCode = keccak256("LogMock(uint256,uint256,uint256,uint256)"); bytes32 eventCode = keccak256("LogMock(uint256,uint256,uint256,uint256)");
bytes memory eventData = abi.encode(mockNumber, mockBalance, getId, setId); bytes memory eventData = abi.encode(mockNumber, mockBalance, getId, setId);