E2E Tests for Web3 Applications
From Author:
We will go through a brief explanation of what is Web3 and the architecture of a web3 application. Then we will talk about how to end-to-end test, its challenges, some test tools that are available, and a demo using cypress and metamask.
Agenda: What is Web3; The Architecture of a Web3 Application; Web3 E2E Tests Introduction; Web3 E2E Tests Challenges; E2E Test Tools; Demo.
This talk has been presented at TestJS Summit 2022, check out the latest edition of this Tech Conference.
FAQ
Web3 is the new version of the web that incorporates decentralization, token-based economics, and blockchain technology. It emphasizes a read-write-own model, allowing users more control and ownership over their data and the online communities they are part of.
In Web3 applications, the architecture is centered around smart contracts and the Ethereum blockchain. Unlike traditional web applications that have a front-end, back-end, and database controlled by a corporation, Web3 applications have a decentralized structure where the front-end interacts with smart contracts on the Ethereum blockchain.
The main challenge in end-to-end testing for Web3 applications is the integration with third-party providers like MetaMask, which are necessary for blockchain interactions and transaction submissions. Current test frameworks often struggle to fully integrate these third-party plugins, especially in headless browser environments.
For end-to-end testing of Web3 applications, tools like SynPress can be used. SynPress is a wrapper from Cypress IO that supports integration with MetaMask. Alternatively, developers can use typical testing frameworks like Jest or Mocha for unit tests, and mock strategies for integration tests.
Using a mock in Web3 application testing allows developers to simulate blockchain interactions without relying on real third-party integrations. This approach reduces dependencies, helps avoid issues related to third-party downtimes or bugs, and speeds up the testing process.
Using real third-party integrations in Web3 testing provides a more accurate real-world scenario but can lead to slower test execution and dependency on third-party reliability. Mocks, on the other hand, offer faster testing and independence from third-party issues but might not mimic real-world interactions as precisely.
Video Transcription
1. Introduction to Web3
I'm Rafaela, a QA professional with 15 years of experience in test automation, strategy, and leadership. I created a blog in 2011 to share my knowledge in QA, programming, DevOps, and test automation. In this part, we'll discuss Web3, its decentralized and token-based model, and the evolution of the web. We'll also explore the architecture of Web3, which is based on smart contracts and offers more privacy and security.
Hello, everybody. I'm Rafaela, and I'm gonna share a bit of my experience with end-to-end tests for Web3 applications. So just a bit about me. I have 15 years experience in QA, test automation, test strategy, architecture, and leadership, and I got really passionate about the QA area, so I created this blog in 2011 where, you know, you can find everything that I have learned in the past couple of years.
So code snippets, programming, DevOps, leadership, and test automation, of course. I was born and raised in Brazil, to be more specific, I'm from a coastal city called Santos in Sao Paulo. And you can see the picture on the screen. I'm also a really big fan of Harry Potter, as you can see, and this is one of the reasons why I moved to London eight years ago. And the weather as well, but nobody believed when I said that.
But yeah, the agenda is going to be this one. We are going to talk about what is Web3, then the architecture of the Web3 application, some introduction about the entry-in tests, and the challenge, then the tools that you can use, and we are going to have two demos, one just using a mock, and another one using a framework called SyncPress. And then in the end, we are going to talk about the tradeoffs of each approach.
So what is Web3? Web3 is just a new version of the web. We are on Web2 right now and this Web3 comes with the ideas of decentralization, token-based economics and also blockchain technology. So it offers a read-write-own model, so people, they have financial stake and more power over the online communities they belong to. So they own the data, which is not the case right now. The online experience is expected to change as cell phones and smartphones and the pieces they did in the past, so it's going to be a big change for, you know, us that we are living in this moment.
Some business they try to join this new market but they encounter some pushbacks as you know with blockchain as well. Like, you know, the negative impact on the environment and the financial speculation as well. This is the evolution of the web. So from the first version to now, so the first version we had the static read-only pages where you couldn't interact too much with them. And then now what we have is a bit more dynamic and interactive so we can go there and post things. So, you know, Twitter, we can just send our data away basically through these big corporations. And the Web3, which is the one coming now, is more private, secure and decentralized. So the idea is, you know, our data is not going to be owned by these big corporations but by yourself.
And the architecture of the Web3 is also quite different because it's based on smart contracts like blockchain. So if we see now what we have is basically the front-end, back-end database inside of this web server. And this is controlled by, you know, the corporation or the company, somebody. And the Web3, we have just the front-end in the web server. So this is going to still be part of the, you know, it's going to be controlled by the company or the corporation.
2. Web3 Architecture and Testing Challenges
The smart contracts in Web3 are decentralized and handle the business logic of transactions. Interactions with the front-end are then passed to the smart contracts and the Ethereum virtual machine (EVM), which adds transactions to the blockchain. The Web3 stack consists of layers such as centralized applications, cryptocurrency wallets like MetaMask, and developer environments. Unit and UI tests can be performed using familiar frameworks, while integration tests can use smart contract libraries. However, full end-to-end tests face challenges due to the need for third-party providers like MetaMask. Faking UI interactions is complex, and existing test frameworks do not support these plugins. One approach is to mock the Web3 flow, where the user interacts with the Web3, which then interacts with MetaMask or the third-party provider to send transactions to the Ethereum blockchain.
But then the smart contracts, the EVM and the Ethereum blockchain, this is something that is going to be decentralized. And the smart contracts, they have the business logic, or the protocol of these transactions and these business. So basically now, what we have is just we are going to interact with the front-end and then the front-end is going to interact with the smart contracts, and then EVM, the Ethereum virtual machine, and this is going to add the transaction to the blockchain. So it's going to add a new block to this Ethereum blockchain. And this is the part where it's decentralized.
So this is an example of a WebTree stack. So we have some examples of like tools and frameworks, but you can see the layers. So you have the first layer with the centralized applications. So it can be something like MetaMask, which is a plugin to authorize it. Identity have wallets, it's a cryptocurrency wallet. Then you have Uniswap. Then you have another layer presentation layer, which is called then you have the developer environments where you can, you know, test your product. And then you have the other layers like blockchain interaction layer. And the network layer with the EVM blockchains. So this is not all the tools that you can use. It's just like an example with the most popular ones, I believe. But at least you have an idea of, you know, how it is their Web3 stack.
And then the tasks, they are, the end-to-end tasks are more like the problem with Web3. And if you want to do, you know, the unit tests, it's fine, you can use something that you already use it for, you know, web2 applications. You can use Jest, you can use Mocha, it's the same kind of framework. And then you can just verify, you know, if the components they are operating as intended. So UI tests are also not a problem, because you can still use the same frameworks that you use right now to do the tests. And, yeah, the integration tests, they are not a problem as well, because you can just use the smart contract libraries to mimic their own changes by just mocking the underlying EVM. So the problem is when you go and you try to do the full end-to-end tests without the mocking, because you have this third party provider that you need to use to communicate with the blockchain and submit the transactions, and most of the frameworks right now that do end-to-end tests, they cannot access this plugin. So one of the most used plugins is MetaMask, as I said, it's a cryptocurrency wallet, and you need these to interact with the Ethereum blockchain and sign the private keys and do the full transaction cycle flow. So yeah, faking these UI interactions is really complex and the test frameworks that we have right now, they don't support these plugins, even when running headless browser. So one of the approaches that I'm going to show you after is just mocking the WebTree. But this is basically what is the flow. So the user goes in and interacts with the WebTree that interacts with the MetaMask or the third-party provider. And then finally, MetaMask is able to send this transaction to the Ethereum blockchain and add the block there.
Available in other languages:
Check out more articles and videos
We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career
Workshops on related topic
In this three-hour workshop we’ll introduce React Testing Library along with a mental model for how to think about designing your component tests. This mental model will help you see how to test each bit of logic, whether or not to mock dependencies, and will help improve the design of your components. You’ll walk away with the tools, techniques, and principles you need to implement low-cost, high-value component tests.
Table of contents- The different kinds of React application tests, and where component tests fit in- A mental model for thinking about the inputs and outputs of the components you test- Options for selecting DOM elements to verify and interact with them- The value of mocks and why they shouldn’t be avoided- The challenges with asynchrony in RTL tests and how to handle them
Prerequisites- Familiarity with building applications with React- Basic experience writing automated tests with Jest or another unit testing framework- You do not need any experience with React Testing Library- Machine setup: Node LTS, Yarn
Points Covered:
1. Introduction to JavaScript Patterns2. Foundational Patterns3. Object Creation Patterns4. Behavioral Patterns5. Architectural Patterns6. Hands-On Exercises and Case Studies
How It Will Help Developers:
- Gain a deep understanding of JavaScript patterns and their applications in real-world scenarios- Learn best practices for organizing code, solving common challenges, and designing scalable architectures- Enhance problem-solving skills and code readability- Improve collaboration and communication within development teams- Accelerate career growth and opportunities for advancement in the software industry
Tests rely on many conditions and are considered to be slow and flaky. On the other hand - end-to-end tests can give the greatest confidence that your app is working. And if done right - can become an amazing tool for boosting developer velocity.
Detox is a gray-box end-to-end testing framework for mobile apps. Developed by Wix to solve the problem of slowness and flakiness and used by React Native itself as its E2E testing tool.
Join me on this workshop to learn how to make your mobile end-to-end tests with Detox rock.
Prerequisites- iOS/Android: MacOS Catalina or newer- Android only: Linux- Install before the workshop
Comments