{"id":476,"date":"2023-02-23T11:55:29","date_gmt":"2023-02-23T09:55:29","guid":{"rendered":"https:\/\/ackeeblockchain.com\/blog\/?p=476"},"modified":"2024-05-16T13:24:21","modified_gmt":"2024-05-16T11:24:21","slug":"woke-2-0-development-and-testing-framework-for-solidity","status":"publish","type":"post","link":"https:\/\/ackee.xyz\/blog\/woke-2-0-development-and-testing-framework-for-solidity\/","title":{"rendered":"Wake 2.0, development and testing framework for Solidity"},"content":{"rendered":"<p><strong>Note: Woke has been rebranded to Wake.<\/strong><\/p>\n<p>With Wake 2.0, we introduced an updated version of <a title=\"Woke, development &amp; testing framework for Solidity\" href=\"https:\/\/ackeeblockchain.com\/blog\/woke-our-development-and-testing-framework-for-solidity\/\">our Python-based development and testing framework.\u00a0<\/a><\/p>\n<p><strong>Let&#8217;s look closely and find out how it differs from other Python-based testing frameworks and what are <a title=\"Woke, development &amp; testing framework for Solidity\" href=\"https:\/\/ackeeblockchain.com\/blog\/woke-our-development-and-testing-framework-for-solidity\/\">Wake&#8217;s<\/a> advantages.\u00a0<\/strong><\/p>\n<h4><b>Pytypes<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Wake testing framework builds on the so-called <code>pytypes<\/code>. These are automatically generated Python files representing Solidity contracts, structs, enums, etc. in the Python world. Files in the <code>pytypes<\/code> directory are organized in such a way so that it reflected the directory structure of the original Solidity sources. <code>pytypes<\/code> not only provide auto-completion and type hints support but also work as standalone objects that do not need any external files (Solidity source files, for example). All necessary information is included in <code>pytypes.<\/code><\/span><\/p>\n<p><span style=\"font-weight: 400;\">To generate <code>pytypes<\/code> for a project in a current working directory, one can you the <code>wake init pytypes<\/code> command. An optional <code>-w<\/code><\/span><span style=\"font-weight: 400;\"> or <code>--watch<\/code> option launches the <code>pytypes<\/code> generator in watch mode. Solidity source files are watched for changes and <code>pytypes<\/code> are automatically re-generated.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Wake testing framework was inspired by <a href=\"https:\/\/github.com\/eth-brownie\/brownie\" target=\"_blank\" rel=\"noopener\">Brownie<\/a>, thus the way it interacts with the contracts may be familiar to Brownie users. However, as Wake learned from Brownie&#8217;s mistakes, there are some crucial differences and improvements.<\/span><\/p>\n<h4><b>Getting started with Wake\u00a0<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">First, a contract must be imported from <code>pytypes<\/code>. Importing contracts from different namespaces (modules) is essential as it helps to avoid name clashes.<\/span><\/p>\n<p><script src=\"https:\/\/gist.github.com\/encryptedbae\/74899955739df68e4b259a9b1d2edf16.js\"><\/script><\/p>\n<p><span style=\"font-weight: 400;\">Like Brownie, Wake testing framework uses <a href=\"https:\/\/docs.pytest.org\/en\/7.2.x\/\" target=\"_blank\" rel=\"noopener\">pytest<\/a> to collect tests and offer various features like fixtures. From the very beginning, Wake testing framework was designed to support multichain (cross-chain) testing. Still, it is expected that most of the tests will perform single-chain testing. There is a <code>default_chain<\/code> global object that should be used for single-chain testing. It can be imported from the <code>wake.testing<\/code>\u00a0module along with all other objects one may need.<\/span><\/p>\n<p><script src=\"https:\/\/gist.github.com\/encryptedbae\/fc329768eff513af4ebace9bd6f765a4.js\"><\/script><\/p>\n<p><span style=\"font-weight: 400;\"><code>default_chain<\/code><\/span><span style=\"font-weight: 400;\">\u00a0can be either connected to an already running dev chain or launch a new dev chain.<\/span><\/p>\n<p><script src=\"https:\/\/gist.github.com\/encryptedbae\/a5484f4b53e84ce6f22987dba87c07f4.js\"><\/script><\/p>\n<p><span style=\"font-weight: 400;\">With the default configuration, Wake uses Anvil as the development chain. Anvil is a part of the <a href=\"https:\/\/getfoundry.sh\/\" target=\"_blank\" rel=\"noopener\">Foundry<\/a> project. It is highly recommended to keep Anvil up-to-date: Wake development team co-operates with Anvil developers to ensure a seamless experience when writing tests.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">With <code>default_chain<\/code> connected to a dev chain, it is easy to deploy the first contract using Wake testing framework.<\/span><\/p>\n<p><script src=\"https:\/\/gist.github.com\/encryptedbae\/338cd7a5e48bccb25d1241d3f500e2e3.js\"><\/script><\/p>\n<h4><b>Main differences from Brownie<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">The previous example shows another difference from Brownie. Any additional data that modify a transaction or call are passed using keyword arguments instead of a dictionary. By default, <code>pure<\/code> and <code>view<\/code> Solidity functions (including public state variable getters) are called using <code>eth_call<\/code>, i.e. a transaction is not sent. The <code>request_type<\/code> keyword can override this.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Another significant difference from Brownie is that <code>pytypes<\/code> function calls that send a transaction return the function return value instead of a transaction object. Setting <code>return_tx=True<\/code> in a function call or even generating <code>pytypes<\/code> with <code>return_tx<\/code> implicitly set: <code>wake init pytypes --return-tx<\/code>\u00a0can override this.\u00a0<\/span><\/p>\n<p><script src=\"https:\/\/gist.github.com\/encryptedbae\/d9d2662967297e87b82a47591aaf5cf3.js\"><\/script><\/p>\n<p><span style=\"font-weight: 400;\">This example may show yet another advantage of Wake testing framework: it was designed to be very fast. There are a few things to keep in mind in order to achieve maximum performance:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Anvil should be used whenever possible<\/span><\/li>\n<li>Transaction events should be accessed only when necessary; working with <code>tx.events<\/code>\u00a0may be slow in some cases<\/li>\n<li>Transactions should be mainly sent from pre-generated accounts (<code>default_chain.accounts<\/code>); sending a transaction from any other account is possible but at the expense of poorer performance.<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Thanks to <code>pytypes<\/code>, transaction events can be worked with using native Python objects, dataclasses. <code>events<\/code> is the property of a transaction object received either by setting <code>return_tx=True<\/code> or by defining <code>tx_callback<\/code>.<\/span><\/p>\n<p><script src=\"https:\/\/gist.github.com\/encryptedbae\/3edf5434767c6a6c9d83f989e8c7b3cc.js\"><\/script><\/p>\n<p><span style=\"font-weight: 400;\"><code>tx_callback<\/code> is automatically called for transactions that do not have <code>return_tx=True<\/code> set. User-defined errors are also generated in the form of dataclasses. Additionally, there are two internal types of errors: <code>Error(str)<\/code> and <code>Panic(int)<\/code>. Errors are automatically raised as exceptions with <code>return_tx<\/code> set to <code>False<\/code>. There are helper context managers, <code>must_revert<\/code> and <code>may_revert<\/code>, to make handling exceptions easier.<\/span><\/p>\n<p><script src=\"https:\/\/gist.github.com\/encryptedbae\/1329ff1d9ba3e12685edeb64ec10cf75.js\"><\/script><\/p>\n<p><span style=\"font-weight: 400;\">The mentioned above covers the key differences between Wake and Brownie. Be sure to check out our <a href=\"https:\/\/ackeeblockchain.com\/woke\/docs\/latest\/testing-framework\/overview\/\">documentation<\/a> and follow our <a href=\"https:\/\/twitter.com\/AckeeBlockchain\/\" target=\"_blank\" rel=\"noopener\">Twitter<\/a> to stay updated.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: Woke has been rebranded to Wake. With Wake 2.0, we introduced an updated version of our Python-based development and testing framework.\u00a0 Let&#8217;s look closely and find out how it differs from other Python-based testing frameworks and what are Wake&#8217;s advantages.\u00a0 Pytypes Wake testing framework builds on the so-called pytypes. These are automatically generated Python files representing Solidity contracts, structs, enums, etc.&hellip;<\/p>\n","protected":false},"author":15,"featured_media":477,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[65,80,103],"tags":[123,104],"class_list":["post-476","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcements","category-solidity","category-wake","tag-developer-tooling","tag-wake"],"aioseo_notices":[],"featured_image_src":"https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/02\/Woke-2.0-600x400.png","featured_image_src_square":"https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/02\/Woke-2.0-600x600.png","author_info":{"display_name":"Aleksandra Yudina","author_link":"https:\/\/ackee.xyz\/blog\/author\/aleksandra-yudina\/"},"_links":{"self":[{"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/posts\/476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/comments?post=476"}],"version-history":[{"count":0,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/posts\/476\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/media\/477"}],"wp:attachment":[{"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/media?parent=476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/categories?post=476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/tags?post=476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}