Code Review: Clear null Account

in #steem7 years ago

I thought I'd go through some of the blockchain test logic to see if I can explain it. Hopefully I can interpret it clearly enough without too much jargon. In doing so, maybe I'll be able to spell out certain details for my readers.

In this example, we're looking at how it's important that the @null balance always gets zeroed out. It's part of consensus that its balance always becomes zero, no matter how funds are transferred to it. This is known as burning assets.

The logic I'm interpreting here comes from this code revision:

https://github.com/steemit/steem/blob/d04a62953c3b9ec9aab8ba8051848d8d1da18f0c/tests/tests/operation_time_tests.cpp#L2854


Case: clear_null_account

The name of this verification routine is clear_null_account. It is intended to check if the blockchain behavior really does what the developers expect. Specifically, the developers want to know if the null account really has a zero balance.

Setup Phase:

  1. Alice (alice) is summoned into existence as a blockchain actor.
  2. Generate a block (simulates 3 seconds of time).
  3. Assets are summoned into existence, to fund alice:
  • 10.000 TESTS (similar to STEEM on testnet)
  • 10.000 TBD (similar to SBD on testnet)
  1. Regular transfer operation created:
  • From alice to null in the amount of 1.000 TESTS.
  • From alice to null in the amount of 2.000 TBD.
  1. STEEM Power transfer operation created (applied to null as VESTS):
  • From alice to null in the amount of 3.000 TESTS.
  1. Savings transfer operation created:
  • From alice to null in the amount of 4.000 TESTS.
  • From alice to null in the amount of 5.000 TBD.
  1. Assets are summoned into existence, to further fund null in addition to what alice transferred above:
  • 1.000 TESTS
  • 1.000 TBD
  • 1.000000 VESTS (as vesting balance)
  • 1.000 TESTS (as vesting STEEM)
  1. Assets are summoned into existence, to fund the blockchain:
  • 2.000 TESTS into the current supply.
  • 3.000 TESTS into the virtual supply.
  • 1.000 TBD into the current supply.
  • 1.000000 VESTS into the rewarded vesting shares.
  • 1.000 TESTS into the rewarded vesting STEEM.

Test Phase:

  1. Generate a block (simulates another 3 seconds of time), which clears all balances of null.
  2. Check to see if all null balances are now zero (including VESTS).
  3. Check to see if all null reward balances are now zero (including VESTS).
  4. Check to see if:
  • Balance of alice is 2.000 TESTS
  • Balance of alice is 3.000 TBD

If all of the above takes place, the test case passes and we are now sure that the null balance behaves as we expect.


Conclusion

Going through this simple test I did learn something. I knew that there were several methods of transferring assets. But it hadn't occurred that each asset was really zeroed out for null.

This is because we typically only send SBD (TBD on testnet) to null for post promotion. But the blockchain supports all asset types, so even reward balances and VESTS are checked.

It makes sense that this is the case and it's great to see that this behavior is explicitly being evaluated in the tests.

Sort:  

I think this post has beyond my knowledge.

Really don't know what is going on here.
But I am quite sure this is a quality post.

lol

What if the null balance doesn't get zeroed out?

Then they see an error when they run the tests.

Great post, sorry I still do not understand anything. I still get there.

i consider myself something of a nerd but this went flying way above my head! You are a guru. Will try to do some background research on blockchain tests and then attempt again. Perhaps you can do an article explaining the basics for newbies. It will be very helpful. Thanks

Would love to see more posts from you. Following you. Please feel free to follow me and see my posts today if you like interesting wildlife pictures with a story like this one https://steemit.com/wildlife/@vm2904/riding-high-free-ride-with-a-meal-of-ticks, https://steemit.com/bwphotocontest/@vm2904/bwphotocontest-nature-s-artwork-of-symmetry-the-passionflower and https://steemit.com/photography/@vm2904/attitude-the-meek-shall-rule-the-earth
Please provide your comments, upvote and resteem if you like any of my blogs

This post received a 25% upvote from @randowhale thanks to @kurtbeil! For more information, click here!

nice article . kindly follow me back it will b my pleasure