TransWikia.com

Observing some odd behaviour in ether transfer, could somebody help to explain it

Ethereum Asked by shamb0 on December 16, 2020

I have simple piece of example code derived from SWC-136 · Overview, complete buidler based workspace in the git repo. I see some misbehavior in the execution [ ether transfer between usr-acc -> contract -> usr-acc ] is not as expected …

Could somebody help to figure out or explain misbehavior of the code

Log Trace

main $ env DEBUG="info*,debug*,error*" yarn run test test/OddEven.spec.ts
yarn run v1.22.4
$ yarn run test:contracts test/OddEven.spec.ts
$ cross-env SOLPP_FLAGS="FLAG_IS_TEST,FLAG_IS_DEBUG" buidler test --show-stack-traces test/OddEven.spec.ts
$(process.argv.length)
All contracts have already been compiled, skipping compilation.


  unencrypted-secrets Test
  info:Unencrypted-Secrets-Test Admin :: 0x17ec8597ff92C3F44523bDc65BF0f1bE632917ff +0ms
  info:Unencrypted-Secrets-Test Usr1 :: 0x63FC2aD3d021a4D7e64323529a55a9442C444dA0 +1ms
  info:Unencrypted-Secrets-Test Usr2 :: 0xD1D84F0e28D6fedF03c73151f98dF95139700aa7 +0ms
  info:Unencrypted-Secrets-Test Usr3 :: 0xd59ca627Af68D29C547B91066297a7c469a7bF72 +0ms
  debug:Unencrypted-Secrets-Test Network Gas price @ 8000000000 +0ms
  debug:Unencrypted-Secrets-Test Network Gas price @ 0.000000008 +0ms
  debug:Unencrypted-Secrets-Test S1-Ent wallet bal :: 200.0 +5ms
  debug:Unencrypted-Secrets-Test OddEven @ 0xA193E42526F1FEA8C99AF609dcEabf30C1c29fAA +47ms
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +3ms
  debug:Unencrypted-Secrets-Test S1-Ext wallet bal :: 199.997445816 +2ms
  debug:Unencrypted-Secrets-Test S2-Ent :: 199.997445816 +2ms
  debug:Unencrypted-Secrets-Test S2-Ent usr1 bal :: 200.0 +3ms
  debug:Unencrypted-Secrets-Test S2.2 nounce :: 0 +4ms
arg addr[0x63fc2ad3d021a4d7e64323529a55a9442c444da0] val[2]
Cont bal[10000000000000000000]
addr[0x63fc2ad3d021a4d7e64323529a55a9442c444da0]::numb[2]
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +37ms
  debug:Unencrypted-Secrets-Test S2-Ext usr1 bal :: 200.0 +3ms
  debug:Unencrypted-Secrets-Test S2-Ext :: 200.0 +3ms
    ✓ tst-item-001-usr1-play (52ms)
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +2ms
  debug:Unencrypted-Secrets-Test S3-Ext wallet bal :: 199.997445816 +3ms
  debug:Unencrypted-Secrets-Test S2-Ent :: 199.997445816 +3ms
  debug:Unencrypted-Secrets-Test S2-Ent usr2 bal :: 200.0 +2ms
  debug:Unencrypted-Secrets-Test S2.2 nounce :: 0 +4ms
arg addr[0xd1d84f0e28d6fedf03c73151f98df95139700aa7] val[10]
Cont bal[10000000000000000000]
addr[0xd1d84f0e28d6fedf03c73151f98df95139700aa7]::numb[10]
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +28ms
  debug:Unencrypted-Secrets-Test S2-Ext usr2 bal :: 200.0 +3ms
  debug:Unencrypted-Secrets-Test S2-Ext :: 199.997445816 +1ms
    ✓ tst-item-001-usr2-play (41ms)
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +3ms
  debug:Unencrypted-Secrets-Test S3-Ext wallet bal :: 199.997445816 +3ms
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +2ms
  debug:Unencrypted-Secrets-Test S4-Ext wallet bal :: 199.997445816 +2ms


  2 passing (354ms)

Done in 7.81s.

Print in constructor, to confirm contract deployed once

main$ env DEBUG="info*,error*,debug*" yarn run test test/OddEven.spec.ts 
yarn run v1.22.4
$ yarn run test:contracts test/OddEven.spec.ts
$ cross-env SOLPP_FLAGS="FLAG_IS_TEST,FLAG_IS_DEBUG" buidler test --show-stack-traces test/OddEven.spec.ts
$(process.argv.length)
All contracts have already been compiled, skipping compilation.


  unencrypted-secrets Test
  info:Unencrypted-Secrets-Test Admin :: 0x17ec8597ff92C3F44523bDc65BF0f1bE632917ff +0ms
  info:Unencrypted-Secrets-Test Usr1 :: 0x63FC2aD3d021a4D7e64323529a55a9442C444dA0 +1ms
  info:Unencrypted-Secrets-Test Usr2 :: 0xD1D84F0e28D6fedF03c73151f98dF95139700aa7 +0ms
  info:Unencrypted-Secrets-Test Usr3 :: 0xd59ca627Af68D29C547B91066297a7c469a7bF72 +0ms
  debug:Unencrypted-Secrets-Test Network Gas price @ 8000000000 +0ms
  debug:Unencrypted-Secrets-Test Network Gas price @ 0.000000008 +0ms
  debug:Unencrypted-Secrets-Test S1-Ent wallet bal :: 200.0 +5ms
OddEven const owner addr[0x17ec8597ff92c3f44523bdc65bf0f1be632917ff]
  debug:Unencrypted-Secrets-Test OddEven @ 0xA193E42526F1FEA8C99AF609dcEabf30C1c29fAA +73ms
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +5ms
  debug:Unencrypted-Secrets-Test S1-Ext wallet bal :: 199.997080544 +3ms
  debug:Unencrypted-Secrets-Test S2-Ent :: 199.997080544 +3ms
  debug:Unencrypted-Secrets-Test S2-Ent usr1 bal :: 200.0 +3ms
  debug:Unencrypted-Secrets-Test S2.2 nounce :: 0 +5ms
arg addr[0x63fc2ad3d021a4d7e64323529a55a9442c444da0] val[2]
Cont bal[10000000000000000000]
addr[0x63fc2ad3d021a4d7e64323529a55a9442c444da0]::numb[2]
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +31ms
  debug:Unencrypted-Secrets-Test S2-Ext usr1 bal :: 200.0 +3ms
  debug:Unencrypted-Secrets-Test S2-Ext :: 200.0 +3ms
    ✓ tst-item-001-usr1-play (47ms)
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +2ms
  debug:Unencrypted-Secrets-Test S3-Ext wallet bal :: 199.997080544 +3ms
  debug:Unencrypted-Secrets-Test S2-Ent :: 199.997080544 +3ms
  debug:Unencrypted-Secrets-Test S2-Ent usr2 bal :: 200.0 +3ms
  debug:Unencrypted-Secrets-Test S2.2 nounce :: 0 +3ms
arg addr[0xd1d84f0e28d6fedf03c73151f98df95139700aa7] val[10]
Cont bal[10000000000000000000]
addr[0xd1d84f0e28d6fedf03c73151f98df95139700aa7]::numb[10]
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +27ms
  debug:Unencrypted-Secrets-Test S2-Ext usr2 bal :: 200.0 +2ms
  debug:Unencrypted-Secrets-Test S2-Ext :: 199.997080544 +2ms
    ✓ tst-item-001-usr2-play (40ms)
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +2ms
  debug:Unencrypted-Secrets-Test S3-Ext wallet bal :: 199.997080544 +2ms
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +2ms
  debug:Unencrypted-Secrets-Test S4-Ext wallet bal :: 199.997080544 +3ms


  2 passing (535ms)

Done in 8.06s.

Two times invocation of play in Single test

main$ env DEBUG="info*,error*,debug*" yarn run test test/OddEvenV2.spec.ts 
yarn run v1.22.4
$ yarn run test:contracts test/OddEvenV2.spec.ts
$ cross-env SOLPP_FLAGS="FLAG_IS_TEST,FLAG_IS_DEBUG" buidler test --show-stack-traces test/OddEvenV2.spec.ts
$(process.argv.length)
All contracts have already been compiled, skipping compilation.


  unencrypted-secrets Test
  info:Unencrypted-Secrets-Test Admin :: 0x17ec8597ff92C3F44523bDc65BF0f1bE632917ff +0ms
  info:Unencrypted-Secrets-Test Usr1 :: 0x63FC2aD3d021a4D7e64323529a55a9442C444dA0 +0ms
  info:Unencrypted-Secrets-Test Usr2 :: 0xD1D84F0e28D6fedF03c73151f98dF95139700aa7 +0ms
  info:Unencrypted-Secrets-Test Usr3 :: 0xd59ca627Af68D29C547B91066297a7c469a7bF72 +0ms
  debug:Unencrypted-Secrets-Test Network Gas price @ 8000000000 +0ms
  debug:Unencrypted-Secrets-Test Network Gas price @ 0.000000008 +0ms
  debug:Unencrypted-Secrets-Test S1-Ent wallet bal :: 200.0 +5ms
OddEven@constructor owner addr[0x17ec8597ff92c3f44523bdc65bf0f1be632917ff]
  debug:Unencrypted-Secrets-Test OddEven @ 0xA193E42526F1FEA8C99AF609dcEabf30C1c29fAA +70ms
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +5ms
  debug:Unencrypted-Secrets-Test S1-Ext wallet bal :: 199.997079024 +3ms
  debug:Unencrypted-Secrets-Test S2-Ent :: 199.997079024 +2ms
  debug:Unencrypted-Secrets-Test S2-Ent usr1 bal :: 200.0 +2ms
  debug:Unencrypted-Secrets-Test S2.2 nounce :: 0 +4ms
arg addr[0x63fc2ad3d021a4d7e64323529a55a9442c444da0] val[2]
Cont bal[10000000000000000000]
addr[0x63fc2ad3d021a4d7e64323529a55a9442c444da0]::numb[2]
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +30ms
  debug:Unencrypted-Secrets-Test S2-Ext usr1 bal :: 200.0 +2ms
  debug:Unencrypted-Secrets-Test ======================== Usr2 Trans ======================== +0ms
  debug:Unencrypted-Secrets-Test S2-Ent usr2 bal :: 200.0 +3ms
  debug:Unencrypted-Secrets-Test S2.2 nounce :: 0 +4ms
arg addr[0xd1d84f0e28d6fedf03c73151f98df95139700aa7] val[10]
Cont bal[10000000000000000000]
addr[0xd1d84f0e28d6fedf03c73151f98df95139700aa7]::numb[10]
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +30ms
  debug:Unencrypted-Secrets-Test S2-Ext usr2 bal :: 200.0 +2ms
  debug:Unencrypted-Secrets-Test S2-Ext :: 199.997079024 +2ms
    ✓ tst-item-001-usr1-play (81ms)
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +2ms
  debug:Unencrypted-Secrets-Test S3-Ext wallet bal :: 199.997079024 +2ms
  debug:Unencrypted-Secrets-Test OddEven balance :: 0.0 +3ms
  debug:Unencrypted-Secrets-Test S4-Ext wallet bal :: 199.997079024 +3ms


  1 passing (361ms)

Done in 7.83s.

One Answer

It looks like your contract is redeployed anew for every test. You need to do two invocations of play in a single test to trigger winner selection.

Answered by Mikhail Vladimirov on December 16, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP