On the 30 Apr 2019, I was privileged to attend the 5th session entitled
Testing Smart Contracts
by the newly started Decentralized Apps Development Club (DADC), from 6.30pm to 9.30pm at BitTemple, 5F Republic Plaza.
All pics in this article are from DApps Dev Club
DADC is a twice a month technical book club, started by software engineer Brendan Graetz, and CTO of blockchain consultancy Baypay Inc Kenneth Hu. You can check out their website here. These sessions draw their source material from the book: "Mastering Ethereum" by Andreas Antonopoulos and Gavin Wood and Brendan blogs , tweets at @bguiz and works as a Senior Software Engineer at Autopilot. He started DADC to teach the public about the underlying tech behind blockchain and development of decentralized apps. Kenneth brought in his expertise in organizing meetups, being the founder of the Blockchain & DApps meetup group. and medium group. His LinkedIn
Microsoft, Chainstack, Acronis, Lifelong Learning Institute, BitTemple, National Blockchain Challenge (NBC) '19, Spartan Group, StartupToken, CryptoJobs List, Engineers.SG and Blockchain&DApps have worked together to make this happen.
Brendan and I are in the organizing committee for the 3-day NBC ‘19 from 14 to 16 June, comprising a few blockchain and innovation masterclasses and panel discussions, a 2-day hackathon targeted at tertiary students and a career fair hosting various blockchain and tech organizations (one can sign up as a participant or email your interest to be a panelist/judge at www.globaltechchallenge.com).
Brendan is an impressive teacher – clear and brisk. The audience, from various tech/blockchain companies and educational institutions, loved this initiative and his clear teaching! What’s more, he had volunteers from the SingaporeJS community to guide beginners like me and a chat group within the DADC attendees to clarify their doubts.
I was filled with awe as I sat in for the
Testing Smart Contracts session which,
though may seem advanced to many newbies, is actually
Blockchain 101. In fact,
the entire series covers the basics and that is the intent - they do not go into anything advanced, except perhaps as the
The primary discussion of the session revolved around smart contracts. Smart contracts execute themselves as per terms between
all those who interact with it, directly written into code and are incorruptible as they are based on a blockchain - an immutable
distributed ledger. Smart contracts enable tracing, transparent and irreversible transactions. They are particularly useful in
applications such as voting, where incorruptibility is essential.
Previous sessions had included writing smart contracts in Solidity, a programming language for the Ethereum Virtual Machine,
and used truffle (a framework) to deploy them onto a local blockchain. This session would continue to use truffle,
Brendan began by explaining the features of the git repository and suggesting the downloads of NodeJs, Github, solc, truffle, and ganache. Ganache is a simulated blockchain network - if one were to connect to a physical blockchain network, he/she will be slower and will need to pay, as opposed to the free Ganache and Truffle test. He/she can also connect to a real Ethereum network, though many people prefer not to spend money at the testing phase.
Brendan showed how to test code for a smart contract within a sandbox. Comprising six hands-on exercises, Brendan went through the various concepts thoroughly, and at a good pace. The first lesson learned, was that false positives may occur, where both the testing and implementation carry the same error – this leads to the error being undetected. One solution is to conduct more tests. Brendan also taught how to come up with test cases. Ideally, they should cover as many paths through the code as possible. For many scenarios, however, it is impossible to write an implementation – for instance, you can’t connect to the real database, and hence, you must mock the database. Furthermore, Brendan explained how to write tests in ways that would resist external changes - for example, when running them on a different computer, or after connecting to a different Ethereum network. The event ended with a session where people could come and pitch themselves/their events!
writing test cases for very simple functions
Implementations and specifications
If either is wrong, the
assert code will highlight it.
If they are congruently both wrong, creating a false positive, the only way to detect this would be to conduct more tests.
He then covered the Truffle test, which is 99% mocha and 1% of new things specific to smart contracts, such as artifacts, along with Ganache:
A storyline to illustrate truffle test runner including creating and operating car objects.
Injecting the accounts into a
Clean room environment that the
contract block provides.
Additional challenges on property-based testing and mocking Solidity were given!
I was astounded by how much of expertise in blockchain both the speakers and members of the audience had, judging by the depth of questions asked. They were really helpful, hanging around for more than an hour after the event ended to shed more light on blockchain for me. In this fast-changing world where blockchain is silently becoming more pervasive, it is great for all to have a deeper understanding of it and let our creative sparks fly on what we can do with it! Hence, I would DEFINITELY RECOMMEND all to attend this technical book club DADC every second and fourth Tuesday evening of the month! If you are worried about catching up on what you’ve missed in the past, the videos are uploaded on dappsdev.org and are in fact, streamed on Engineers.SG!
Financial news about publicly listed comapnies in electronics sector.Read
Financial news about publicly listed comapnies in Basic Materials sector.Read
Financial news about publicly listed comapnies in Industrials sector.Read