Closed rudolfix closed 4 years ago
in conversation with FE and backend, we figured the most appropriate solution will be to offer this as a service over an api-endpoint. this will enable e2e tests for the frontend.
Also, we could just write the shift into a soldity function, that way it will be easier tested by the backend-unit tests (i do not understand why yet)
see this PR in backed-repo too: https://github.com/Neufund/platform-backend/pull/2275
here are my notes on solving this task:
===========
ETOState. Setup Whitelist Public Signing Refund Payout
=> for now, implemented in solidity, using startOfInternal js would use startOfStates
trouble as ETOCOmmitment is pretty big…
some tests use CommitmentState.js, whcih abstracts to 4 states vs the 7 defined in ETOStat whcih f to use to understand ETO state? there are various CommitmentState-enums defined, I need to use the one in ``helpers/CommitmentState.js`` -> expectLogStateTransition
yarn build
then run individual test
yarn truffle test –network inprocesstest test/ETO/ETOCommitment.js test/setup.js
does not compile, run solc on it first
extra test here:
it("should move time to right before state transition", async () => {
await deployETO({ ovrArtifact: MockETOCommitment }); const timestamp = await latestTimestamp(); durTable = defaultDurationTable(); startDate = new web3.BigNumber(timestamp + 2 * dayInSeconds); const whitelistD = durTable[CommitmentState.Whitelist].add(1); // set start data to 2 days from now via mocker const startTx = await etoCommitment.mockStartDate( etoTerms.address, equityToken.address, startDate, startDate.add(whitelistD), { from: company }, ); expectLogETOStartDateSet(startTx, company, 0, startDate.add(whitelistD));
// move to right before startDate via helper and wait await etoCommitment.shiftToBeforeNextState(10); await increaseTime(15); const tx = await etoCommitment.handleStateTransitions(); expectLogStateTransition(tx, CommitmentState.Setup, CommitmentState.Whitelist, "ignore");
// do so again for whitelist->public transition await etoCommitment.shiftToBeforeNextState(10); await increaseTime(15); const tx2 = await etoCommitment.handleStateTransitions(); expectLogStateTransition(tx2, CommitmentState.Whitelist, CommitmentState.Public, "ignore" ); });
model upon inspectETO.js which is used like this:
```yarn truffle exec scripts/verifyDeployment.js –network localhost –universe 0x762db45f0ef6c83d64181988195991ef115dc2b3```
?! what does the "exec" option do? -> tells it that it is to be executed?
check https://github.com/Neufund/platform-backend/wiki/5.06.-Use-Case-Investment
-> shift all states so that one can not cause illogical states where a previous state ends before the next one
always use make down before doing things
make down
fire up minimal services: test-unit-services-up
check ext-services here http://localhost:1337/ui/#!/e2e-tests/api_e2etests_eto_time_travel
restart ext-services with wihtout downing everything
make update-service service=devexternalservicesmockapi
use docker ps to get id docker kill id
navigate to /devexternalmockapi and start manually python runapi.py
"type": "platformcontracts.exceptions.PlatformContractsContractNotDeployed"
check py3 docs full instance 4 transactions vs instance (call only) method().transact() method().call()
yaml and in e2etests.py
for this specific endpoint, we need no tests as it will be tested by the frontend implicitly
in general: make test im richtigen verzeichnis make test in root => all
where to get interface from? Tomek send me a bunch of useful links to helper on slack:
or maybe like this function getetofixtureaddress from platformtesting/platformcontracts.py in platform common (edited)  70m3k 1:25 PM def obtainetotermscontract(etoid: str) -> ConciseContract: connector = NeufundContractsConnector(ethereumserviceconfiguration) neufundcontracts = connector.getneufundcontracts() commitmentartifact = neufundcontracts.resolveartifactfrominterface("commitmentInterface", etoid) etocontract = neufundcontracts.getinstance(commitmentartifact, etoid) etotermsaddress = etocontract.etoTerms() termsartifact = neufundcontracts.resolveartifactfrominterface("termsInterface", etotermsaddress) return neufundcontracts.getinstance(termsartifact, etotermsaddress) new messages 1:27 PM again from pyplatformcommon now file platformtesting/utils/ethereumhelpers.py there is getetocontract function with etoaddress as parameter (edited) 1:28 PM and snippet I've sent you earlier could rewritten using getetocontract function 
?? how to increase gas-limit used in migrations? why does it work in the truffle test, but not in the backend-fixture deployment?
DONE gas limit check
parity node vs latest raise
LEARNED:
live mirrors mainnet
everything with test can use DEV things
on both contracts and parity s see task "implement helper function on contract directly"
BLOCKED backend repo can not run truffle properly
?? why is BigNumber always used via web3? ?? How to get the current time in script? Blocktime does not work out of the box, maybe just use unix timestamp -> ask Moe
->
-> deploy frontend!
make update-submodules
make down & make test unit … got an error:
*root*.node-gyp/8.16.2/include/node/v8.h:3370:19: warning: inline function 'void\* v8::Object::GetAlignedPointerFromInternalField(int)' used but never defined
V8INLINE void* GetAlignedPointerFromInternalField(int index);
^~~~~~~~~~
make: * [scrypt.target.mk:121: Release/obj.target/scrypt/src/node-boilerplate/scryptcommon.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/nodemodules/npm/nodemodules/node-gyp/lib/build.js:262:23)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at Process.ChildProcess.handle.onexit (internal/childprocess.js:198:12)
gyp ERR! System Linux 5.0.0-32-generic
gyp ERR! command \"/usr/local/bin/node\" \"/usr/local/lib/nodemodules/npm/nodemodules/node-gyp/bin/node-gyp.js\" \"rebuild\"
gyp ERR! cwd /usr/src/platform-contracts/nodemodules/scrypt
gypmake: Leaving directory '/usr/src/platform-contracts/nodemodules/scrypt/build'
ERR! node -v v8.16.2
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok"
go to backend node at http://localhost:1337/ui/#!/e2e-tests/api_e2etests_eto_time_travel
get deployed contract address from fixture log make run fixtures
nicola uses it via postman
Why we do it We have several under-tested ETO state transition cases that were already an visible on production and are quite hard to add as an permanent fixtures. In essence we want to e2e and manually test following cases
What need to be implemented Implement a CLI in platform contracts repo, similar to
deployETO.js
orinspectETO.js
that when run viatruffle
will mock internal state of ETO to simulate state transitions.Technical Details
On dev networks we deploy
MockETOCommitment
contract insteadETOCommitment
Mock contract, among other things, allows to mock internal timestamps of ETO state machine (See_mockShiftBackTime
). Look for method usage in existing code. For reference please read https://github.com/Neufund/platform-backend/wiki/5.06.-Use-Case-Investment - ETO State machine reference https://github.com/Neufund/platform-contracts/wiki/Smart-Contracts-Catalogue#platformterms-etoterms-durationterms-and-shareholderrights - a kind of primer on ETO ContractsAcceptance Criteria
deployETO
)Testing Manual testing would be enough, you can also unit test shiftting function if it's not yet...
Deployment