<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Przemysław Paczoski on Medium]]></title>
        <description><![CDATA[Stories by Przemysław Paczoski on Medium]]></description>
        <link>https://medium.com/@kodziak?source=rss-ca5cc1972dd2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*hkqMkGzgr3IHD8HNCeE-uA.jpeg</url>
            <title>Stories by Przemysław Paczoski on Medium</title>
            <link>https://medium.com/@kodziak?source=rss-ca5cc1972dd2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 19:44:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kodziak/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Testing NFT Smart Contracts: Common Edge Cases You’re Missing]]></title>
            <link>https://kodziak.medium.com/testing-nft-smart-contracts-common-edge-cases-youre-missing-03fbdaa21639?source=rss-ca5cc1972dd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/03fbdaa21639</guid>
            <dc:creator><![CDATA[Przemysław Paczoski]]></dc:creator>
            <pubDate>Tue, 26 Nov 2024 23:01:11 GMT</pubDate>
            <atom:updated>2024-11-26T23:01:11.992Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re building in this space, you know how critical it is to get your contracts right. But here’s the kicker — a whopping 80% of NFT projects miss crucial edge cases in their testing. Yikes! 😱</p><p>Let’s fix that, shall we? We’ll explore some common pitfalls and how to avoid them. Ready to level up your NFT contract game? Let’s go!</p><h4>1. The Sneaky Approve and Transfer 🕵️‍♂️</h4><p>One of the most overlooked scenarios is when a user approves a transfer, but the transfer doesn’t happen immediately. Here’s what can go wrong:</p><pre>// ❌ Don&#39;t do this:<br>function testApproveAndTransfer() {<br>  // Approve<br>  // Assert approval<br>  // Transfer<br>  // Assert transfer<br>}<br><br>// ✅ Do this instead:<br>function testApproveAndTransferWithDelay() {<br>  // Approve<br>  // Assert approval<br>  // Simulate time passing<br>  // Transfer<br>  // Assert transfer<br>}</pre><p>Why does this matter? In real-world scenarios, there might be a delay between approval and transfer. By simulating this delay, you can catch potential vulnerabilities that only surface when transactions don’t occur back-to-back.</p><h4>2. The Greedy Minter 🤑</h4><p>Ever thought about what happens if someone tries to mint more NFTs than allowed? Many don’t, but you should!</p><pre>// ❌ Incomplete test:<br>function testMint() {<br>  // Mint allowed amount<br>  // Assert success<br>}<br><br>// ✅ Comprehensive test:<br>function testMintWithEdgeCases() {<br>  // Mint allowed amount<br>  // Assert success<br>  // Try to mint one more<br>  // Assert failure with correct error message<br>  // Try to mint max uint256<br>  // Assert failure with correct error message<br>}</pre><p>This test covers not just the happy path, but also attempts to break the system. It’s crucial to ensure your contract handles these edge cases gracefully.</p><h4>3. The Royalty Roundabout 💰</h4><p>Royalties are a big deal in the NFT world, but testing them can be tricky. Here’s an often-missed scenario:</p><pre>// ❌ Basic royalty test:<br>function testRoyalties() {<br>  // Set royalties<br>  // Sell NFT<br>  // Check royalty payment<br>}<br><br>// ✅ Comprehensive royalty test:<br>function testRoyaltiesWithEdgeCases() {<br>  // Set royalties<br>  // Sell NFT<br>  // Check royalty payment<br>  // Change royalty recipient<br>  // Sell NFT again<br>  // Check new recipient gets payment<br>  // Try to set royalties &gt; 100%<br>  // Assert failure<br>}</pre><p>This expanded test covers changing royalty recipients and attempts to set invalid royalty percentages — crucial for maintaining fairness and preventing exploits.</p><h4>4. The Metadata Mayhem 🎭</h4><p>Metadata is the soul of an NFT, but it’s often undertested. Let’s change that:</p><pre>// ❌ Simple metadata test:<br>function testMetadata() {<br>  // Set tokenURI<br>  // Assert tokenURI<br>}<br><br>// ✅ Robust metadata test:<br>function testMetadataEdgeCases() {<br>  // Set valid tokenURI<br>  // Assert tokenURI<br>  // Set empty tokenURI<br>  // Assert failure or default behavior<br>  // Set extremely long tokenURI<br>  // Check gas costs and potential DOS vectors<br>}</pre><p>This comprehensive test ensures your metadata handling is bulletproof, even in extreme scenarios.</p><h4>5. The Ownership Odyssey 🚀</h4><p>Ownership transfers are common, but are you testing all scenarios?</p><pre>// ❌ Basic ownership test:<br>function testOwnership() {<br>  // Transfer ownership<br>  // Assert new owner<br>}<br><br>// ✅ Thorough ownership test:<br>function testOwnershipScenarios() {<br>  // Transfer ownership<br>  // Assert new owner<br>  // Try to transfer ownership as old owner<br>  // Assert failure<br>  // Transfer to zero address<br>  // Assert failure<br>  // Renounce ownership<br>  // Assert owner is zero address<br>  // Try to transfer after renouncing<br>  // Assert failure<br>}</pre><p>This test suite covers various ownership scenarios, including edge cases that could lead to locked contracts or loss of control.</p><h4>Wrapping Up 🎁</h4><p>Testing NFT smart contracts is no walk in the park, but catching these edge cases can save you from major headaches (and potential losses) down the line. Remember, in the world of blockchain, there are no take-backsies!</p><p>By implementing these more comprehensive tests, you’re not just ticking boxes — you’re building a fortress around your NFTs. And in this wild west of Web3, that’s exactly what you need.</p><p>Feeling overwhelmed? Don’t sweat it! This stuff is complex, and it’s okay to need a hand. If you want to dive deeper into Web3 testing strategies or need expert help in securing your NFT projects, head over to <a href="https://web3qa.xyz/">web3qa.xyz</a>. We’re here to help you build rock-solid NFT contracts that stand the test of time (and hackers).</p><p>Stay curious, keep testing, and let’s make the NFT space safer for everyone! 🛡️💎</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03fbdaa21639" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Test Data for DeFi: Beyond Simple ERC20 Mocks]]></title>
            <link>https://kodziak.medium.com/creating-test-data-for-defi-beyond-simple-erc20-mocks-9fbf2f8d3e68?source=rss-ca5cc1972dd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/9fbf2f8d3e68</guid>
            <dc:creator><![CDATA[Przemysław Paczoski]]></dc:creator>
            <pubDate>Thu, 21 Nov 2024 15:04:47 GMT</pubDate>
            <atom:updated>2024-11-21T15:04:47.291Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever felt like your test data is as bland as unseasoned tofu? You’re not alone. A whopping 80% of DeFi projects I’ve audited rely solely on basic ERC20 mocks for testing. But in the wild world of decentralized finance, that’s like bringing a knife to a gunfight. Let’s level up your test game! 🚀</p><h4>The Problem with Simple Mocks</h4><p>Picture this: You’ve built an amazing DEX, tested it with your trusty ERC20 mock, and everything’s green. You deploy… and boom! 💥 Real-world tokens with transfer fees, rebasing mechanisms, or non-standard implementations start flowing in, and suddenly your perfectly tested DEX is about as stable as a house of cards in a hurricane.</p><pre>// ❌ Don&#39;t do this:<br>function testSwap() {<br>  const mockToken = await MockERC20.deploy();<br>  await dex.swap(mockToken.address, amount);<br>  // Assert some basic stuff<br>}<br><br>// ✅ Do this instead:<br>function testSwapWithComplexToken() {<br>  const complexToken = await DeployComplexToken();<br>  await dex.swap(complexToken.address, amount);<br>  // Assert considering token&#39;s unique behavior<br>}</pre><p>In the first example, we’re living in La La Land. In the second, we’re preparing for the DeFi jungle. Let’s dive deeper into creating test data that actually reflects the chaotic beauty of the blockchain.</p><h4>🛠 Crafting Realistic Test Tokens</h4><h4>1. Fee-on-Transfer Tokens</h4><p>Some tokens take a cut on every transfer. Surprise! 🎉</p><pre>contract FeeToken is ERC20 {<br>    uint256 public constant FEE = 100; // 1%<br><br>    function transfer(address recipient, uint256 amount) public override returns (bool) {<br>        uint256 fee = amount * FEE / 10000;<br>        uint256 actualAmount = amount - fee;<br>        <br>        _transfer(_msgSender(), recipient, actualAmount);<br>        _transfer(_msgSender(), address(this), fee);<br>        <br>        return true;<br>    }<br>}</pre><p>When testing with this bad boy, make sure your contracts can handle receiving less than they expected. It’s like ordering a large pizza and getting a medium — disappointing, but you gotta deal with it.</p><h4>2. Rebasing Tokens</h4><p>These tokens adjust everyone’s balance periodically. It’s like your bank account on steroids (or a crash diet).</p><pre>contract RebasingToken is ERC20 {<br>    uint256 public constant REBASE_INTERVAL = 1 hours;<br>    uint256 public lastRebaseTime;<br><br>    function rebase() public {<br>        if (block.timestamp &gt;= lastRebaseTime + REBASE_INTERVAL) {<br>            uint256 supply = totalSupply();<br>            _mint(address(this), supply / 100); // 1% inflation<br>            lastRebaseTime = block.timestamp;<br>        }<br>    }<br>}</pre><p>Testing tip: Make sure to simulate time passages and check how your contracts handle sudden balance changes. It’s like testing your app’s resilience to users who can’t make up their minds.</p><h4>3. Blacklistable Tokens</h4><p>Some tokens come with a built-in bouncer. No entry for you! 🚫</p><pre>contract BlacklistableToken is ERC20 {<br>    mapping(address =&gt; bool) public blacklist;<br>    <br>    function transfer(address recipient, uint256 amount) public override returns (bool) {<br>        require(!blacklist[msg.sender] &amp;&amp; !blacklist[recipient], &quot;Blacklisted!&quot;);<br>        return super.transfer(recipient, amount);<br>    }<br>}</pre><p>When testing, try to swap or provide liquidity with blacklisted addresses. Your contract should handle rejection gracefully, like a seasoned bouncer at an exclusive club.</p><h4>🎭 Simulating Real-World Scenarios</h4><p>Now that we have our exotic token menagerie, let’s put them through their paces:</p><ol><li><strong>Liquidity Crunches</strong>: Simulate a sudden drain of liquidity. How does your AMM handle it?</li><li><strong>Flash Loan Attacks</strong>: Use your test tokens in a flash loan scenario. Can your protocol withstand the pressure?</li><li><strong>Gas Price Spikes</strong>: Mimic Ethereum congestion by manipulating gas prices in your tests. Does your contract prioritize transactions correctly?</li></ol><p>Here’s a quick example of simulating a liquidity crunch:</p><pre>async function testLiquidityCrunch() {<br>  const complexToken = await DeployComplexToken();<br>  const pair = await factory.createPair(weth.address, complexToken.address);<br>  <br>  // Provide initial liquidity<br>  await addLiquidity(weth, complexToken, ethers.utils.parseEther(&quot;100&quot;), ethers.utils.parseEther(&quot;10000&quot;));<br>  <br>  // Simulate large withdrawal<br>  await pair.connect(whale).burn(await pair.balanceOf(whale.address));<br>  <br>  // Now try to swap<br>  await expect(<br>    router.swapExactTokensForTokens(<br>      ethers.utils.parseEther(&quot;1&quot;),<br>      0,<br>      [weth.address, complexToken.address],<br>      user.address,<br>      (await ethers.provider.getBlock(&#39;latest&#39;)).timestamp + 1000<br>    )<br>  ).to.be.revertedWith(&quot;Insufficient Liquidity&quot;);<br>}</pre><p>This test ensures your DEX doesn’t implode when the liquidity suddenly decides to go on vacation.</p><h4>🧠 Why This Matters</h4><p>Creating diverse and realistic test data isn’t just about being a perfectionist (though that helps in DeFi). It’s about:</p><ol><li><strong>Anticipating the Unexpected</strong>: DeFi is where traditional finance meets the Wild West. Prepare for anything.</li><li><strong>Building Trust</strong>: Robust testing translates to reliable protocols. Users trust what doesn’t break.</li><li><strong>Saving Time (and ETH)</strong>: Catching bugs in testnet is way cheaper than explaining to users why their funds are now part of a very expensive lesson.</li></ol><h4>🚀 Leveling Up Your Testing Game</h4><p>Ready to take your DeFi testing to the next level? Here are your marching orders:</p><ol><li>Audit your test suite. How many different token types are you really testing against?</li><li>Create a “token zoo” — a collection of various token implementations to test against.</li><li>Simulate extreme market conditions. What happens to your protocol during a market crash?</li><li>Consider property-based testing to uncover edge cases you haven’t even thought of yet.</li></ol><p>Remember, in DeFi, we’re not just building financial applications; we’re architecting the future of finance. Every test you write is a brick in the foundation of that future.</p><p>Hungry for more DeFi testing wisdom? Want to make your protocols as robust as a cockroach in a nuclear winter? Swing by <a href="https://web3qa.xyz/">web3qa.xyz</a> for more advanced testing strategies, war stories from the trenches, and a community of battle-hardened DeFi testers. Let’s make DeFi unbreakable, one test at a time! 💪🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9fbf2f8d3e68" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gas optimization through testing: how we reduced costs by 40%]]></title>
            <link>https://kodziak.medium.com/gas-optimization-through-testing-how-we-reduced-costs-by-40-ef8c9092e475?source=rss-ca5cc1972dd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef8c9092e475</guid>
            <dc:creator><![CDATA[Przemysław Paczoski]]></dc:creator>
            <pubDate>Wed, 13 Nov 2024 23:01:16 GMT</pubDate>
            <atom:updated>2024-11-13T23:01:16.675Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever felt that punch in the gut when you deploy your smart contract, only to watch gas costs skyrocket? 😱 You’re not alone. In fact, a whopping 80% of Web3 projects struggle with high gas fees, often due to unoptimized code.</p><p>But here’s the kicker — we managed to slash our gas costs by 40% through smart testing. Yep, you read that right. Let’s dive into how we did it, shall we?</p><h4>The Problem: Gas Guzzling Contracts 🚗💨</h4><p>First things first, let’s look at a typical gas-hungry function:</p><pre>// ❌ Gas guzzler alert!<br>function distributeBonuses(address[] memory employees) public {<br>    for (uint i = 0; i &lt; employees.length; i++) {<br>        uint bonus = calculateBonus(employees[i]);<br>        payable(employees[i]).transfer(bonus);<br>    }<br>}</pre><p>This function looks innocent enough, but it’s a silent killer for your gas budget. Why? It’s doing separate transfers for each employee, and that’s expensive on Ethereum.</p><h4>The Solution: Batch Those Transfers! 🚀</h4><p>Here’s how we optimized it:</p><pre>// ✅ Gas saver extraordinaire<br>function distributeBonuses(address[] memory employees, uint[] memory bonuses) public {<br>    require(employees.length == bonuses.length, &quot;Arrays must be same length&quot;);<br>    <br>    for (uint i = 0; i &lt; employees.length; i++) {<br>        payable(employees[i]).transfer(bonuses[i]);<br>    }<br>}</pre><p>What’s the difference? We’re now passing in pre-calculated bonuses, eliminating the need for separate calculateBonus calls for each employee. This might seem small, but in a large organization, it can save a ton of gas.</p><h4>The Testing Strategy 🧪</h4><p>Now, how did we catch this? Enter: Gas Optimization Tests. We set up a test suite that specifically targets gas usage. Here’s a simplified version:</p><pre>import { expect } from &quot;chai&quot;;<br>import { ethers } from &quot;hardhat&quot;;<br><br>describe(&quot;BonusDistributor&quot;, function () {<br>  it(&quot;should optimize gas for bonus distribution&quot;, async function () {<br>    const BonusDistributor = await ethers.getContractFactory(&quot;BonusDistributor&quot;);<br>    const bonusDistributor = await BonusDistributor.deploy();<br><br>    const employees = [addr1.address, addr2.address, addr3.address];<br>    const bonuses = [100, 200, 300];<br><br>    const tx = await bonusDistributor.distributeBonuses(employees, bonuses);<br>    const receipt = await tx.wait();<br><br>    expect(receipt.gasUsed).to.be.below(100000); // Set your gas limit here<br>  });<br>});</pre><p>This test ensures that our distributeBonuses function stays under a specific gas limit. If it ever creeps up, we&#39;ll catch it before deployment.</p><h4>The Results: 40% Gas Savings 💰</h4><p>By implementing this and similar optimizations across our codebase, we saw a dramatic 40% reduction in gas costs. Here’s a quick before and after:</p><p>Scenario Before After Savings 10 employees 500,000 gas 300,000 gas 40% 100 employees 5,000,000 gas 3,000,000 gas 40%</p><h4>Key Takeaways 🗝️</h4><ol><li><strong>Always batch operations</strong> when possible</li><li><strong>Implement gas-specific tests</strong> in your CI/CD pipeline</li><li><strong>Profile your contracts</strong> regularly to catch gas hogs</li><li><strong>Consider off-chain calculations</strong> to reduce on-chain complexity</li></ol><h4>What’s Next? 🚀</h4><p>Gas optimization is an ongoing process. As your project evolves, keep testing and refining. And remember, every little optimization counts!</p><p>Struggling with high gas costs in your Web3 project? Don’t sweat it! At web3qa.xyz, we specialize in helping teams like yours slash gas costs and optimize smart contracts. Let’s chat about how we can supercharge your project’s efficiency!</p><p><a href="https://web3qa.xyz/">Check out web3qa.xyz</a> to learn more about our Web3 testing and optimization services. Your future self (and your users’ wallets) will thank you! 💪</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef8c9092e475" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing smart contract upgrades: a complete testing strategy]]></title>
            <link>https://kodziak.medium.com/testing-smart-contract-upgrades-a-complete-testing-strategy-b1eb9500a307?source=rss-ca5cc1972dd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1eb9500a307</guid>
            <dc:creator><![CDATA[Przemysław Paczoski]]></dc:creator>
            <pubDate>Sat, 09 Nov 2024 15:01:47 GMT</pubDate>
            <atom:updated>2024-11-09T15:01:47.762Z</atom:updated>
            <content:encoded><![CDATA[<p>Ready to level up your smart contract upgrade testing game? You’re in the right place!</p><p>Did you know that over 60% of smart contract vulnerabilities are introduced during upgrades? 😱 That’s a scary number, but don’t worry — I’ve got your back. Let’s dive into a complete testing strategy that’ll help you sleep better at night (and keep your users’ funds safe).</p><h4>Why is testing upgrades so crucial? 🤔</h4><p>Imagine this: You’ve just pushed an upgrade to your DeFi protocol, and suddenly… 💥 BOOM! Users can’t withdraw their funds, or worse, someone’s exploiting a new vulnerability. Not cool, right?</p><p>That’s why we need a rock-solid testing strategy for upgrades. Let’s break it down step by step.</p><h4>1. Baseline Testing 📊</h4><p>Before you even think about upgrading, make sure your current contract is thoroughly tested. This means:</p><ul><li>Unit tests for each function</li><li>Integration tests for complex interactions</li><li>Fuzz testing to catch edge cases</li></ul><p>Here’s a quick example of a baseline test:</p><pre>// ✅ Do this:<br>describe(&quot;TokenVault&quot;, function() {<br>  it(&quot;should allow deposits&quot;, async function() {<br>    const [owner, user] = await ethers.getSigners();<br>    const TokenVault = await ethers.getContractFactory(&quot;TokenVault&quot;);<br>    const vault = await TokenVault.deploy();<br>    await vault.deposit({ value: ethers.utils.parseEther(&quot;1&quot;) });<br>    expect(await vault.balanceOf(owner.address)).to.equal(ethers.utils.parseEther(&quot;1&quot;));<br>  });<br>});</pre><p>Always explain your tests and what they’re checking. This helps your team understand the coverage and importance of each test.</p><h4>2. Upgrade Simulation 🔄</h4><p>Before deploying to mainnet, simulate the upgrade process in a test environment. This includes:</p><ul><li>Deploying the new contract</li><li>Migrating state (if necessary)</li><li>Verifying that all functions work as expected post-upgrade</li></ul><p>Here’s how you might test an upgrade:</p><pre>// ✅ Do this:<br>it(&quot;should maintain user balances after upgrade&quot;, async function() {<br>  const TokenVaultV1 = await ethers.getContractFactory(&quot;TokenVaultV1&quot;);<br>  const vaultV1 = await upgrades.deployProxy(TokenVaultV1);<br>  await vaultV1.deposit({ value: ethers.utils.parseEther(&quot;1&quot;) });<br><br>  const TokenVaultV2 = await ethers.getContractFactory(&quot;TokenVaultV2&quot;);<br>  const vaultV2 = await upgrades.upgradeProxy(vaultV1.address, TokenVaultV2);<br><br>  expect(await vaultV2.balanceOf(owner.address)).to.equal(ethers.utils.parseEther(&quot;1&quot;));<br>});</pre><p>This test ensures that user balances are preserved during the upgrade process. Always check critical state variables and functionality!</p><h4>3. Backwards Compatibility Checks 🔙</h4><p>Upgrades shouldn’t break existing functionality. Test that:</p><ul><li>Old function calls still work</li><li>Events are emitted correctly</li><li>External contract interactions remain intact</li></ul><h4>4. New Feature Testing 🆕</h4><p>For any new features introduced in the upgrade:</p><ul><li>Write comprehensive unit tests</li><li>Perform integration tests with existing functions</li><li>Fuzz test new inputs</li></ul><h4>5. Gas Optimization Verification ⛽</h4><p>Upgrades can sometimes introduce unexpected gas costs. Always check that:</p><ul><li>Function gas costs haven’t increased significantly</li><li>New functions are gas-efficient</li></ul><p>Here’s a simple gas test:</p><pre>// ✅ Do this:<br>it(&quot;should not increase gas costs significantly&quot;, async function() {<br>  const tx = await vaultV2.deposit({ value: ethers.utils.parseEther(&quot;1&quot;) });<br>  const receipt = await tx.wait();<br>  expect(receipt.gasUsed).to.be.below(100000); // Adjust based on your expectations<br>});</pre><h4>6. Security Audits 🔒</h4><p>Don’t skip this step! After your internal testing:</p><ul><li>Conduct a thorough security audit</li><li>Use automated tools like Slither or Mythril</li><li>Consider a manual audit by security experts</li></ul><h4>7. Testnet Deployment 🌐</h4><p>Before hitting mainnet:</p><ul><li>Deploy to testnet</li><li>Run all tests in a live environment</li><li>Encourage community testing and bug bounties</li></ul><h4>8. Upgrade Rehearsal 🎭</h4><p>Practice makes perfect:</p><ul><li>Simulate the entire upgrade process</li><li>Time each step</li><li>Prepare a rollback plan</li></ul><h4>9. Post-Upgrade Verification ✅</h4><p>After the upgrade:</p><ul><li>Run all tests again on the upgraded contract</li><li>Monitor for any unusual activity</li><li>Be ready to respond to user reports</li></ul><p>Remember, testing is not a one-time thing. It’s an ongoing process that continues even after the upgrade is live.</p><h4>Wrapping Up 🎁</h4><p>Testing smart contract upgrades is no joke. It requires a systematic approach, attention to detail, and a healthy dose of paranoia. But with this strategy, you’re well-equipped to handle upgrades like a pro.</p><p>Got questions about implementing this strategy? Need help setting up your testing pipeline? I’m here to help! Check out <a href="https://web3qa.xyz/">web3qa.xyz</a> for more resources on Web3 testing and quality assurance. Let’s make the blockchain a safer place, one test at a time! 💪</p><p>Happy testing, and may your upgrades always be smooth! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1eb9500a307" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated testing setup for smart contracts: a practical guide]]></title>
            <link>https://kodziak.medium.com/automated-testing-setup-for-smart-contracts-a-practical-guide-ce9092cd47b9?source=rss-ca5cc1972dd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce9092cd47b9</guid>
            <dc:creator><![CDATA[Przemysław Paczoski]]></dc:creator>
            <pubDate>Wed, 06 Nov 2024 23:01:24 GMT</pubDate>
            <atom:updated>2024-11-06T23:01:24.093Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, we’re diving into the world of automated testing for smart contracts. If you’re building in Web3, you know how crucial it is to have rock-solid code. Let’s explore how to set up a testing environment that’ll make your smart contracts bulletproof! 🛡️</p><h4>Why Automated Testing for Smart Contracts?</h4><p>Before we jump into the how-to, let’s quickly chat about why this is so important:</p><ol><li><strong>Security</strong>: Smart contracts often handle millions of dollars. One tiny bug could be catastrophic.</li><li><strong>Immutability</strong>: Once deployed, you can’t just push a quick fix. Testing thoroughly before deployment is key.</li><li><strong>Complexity</strong>: DeFi protocols can get pretty wild. Automated tests help manage that complexity.</li></ol><p>Alright, let’s get our hands dirty! 🛠️</p><h4>Setting Up Your Testing Environment</h4><p>First things first, we need to choose our tools. For this guide, we’ll use:</p><ul><li>Hardhat: A development environment for Ethereum</li><li>Chai: An assertion library</li><li>Ethers.js: To interact with our contracts</li></ul><p>Let’s set it up:</p><pre>npm init -y<br>npm install --save-dev hardhat chai @nomiclabs/hardhat-ethers ethers<br>npx hardhat</pre><p>Choose “Create a basic sample project” when prompted.</p><h4>Writing Your First Test</h4><p>Let’s say we have a simple Token contract. Here&#39;s how we might test it:</p><pre>const { expect } = require(&quot;chai&quot;);<br><br>describe(&quot;Token contract&quot;, function() {<br>  it(&quot;Deployment should assign the total supply of tokens to the owner&quot;, async function() {<br>    const [owner] = await ethers.getSigners();<br><br>    const Token = await ethers.getContractFactory(&quot;Token&quot;);<br><br>    const hardhatToken = await Token.deploy();<br><br>    const ownerBalance = await hardhatToken.balanceOf(owner.address);<br>    expect(await hardhatToken.totalSupply()).to.equal(ownerBalance);<br>  });<br>});</pre><p>This test checks if the total supply is assigned to the contract owner upon deployment. Simple, but powerful! 💪</p><h4>Automating Your Tests</h4><p>Now, let’s make sure these tests run automatically. We can use GitHub Actions for this. Create a file .github/workflows/test.yml:</p><pre>name: Smart Contract Tests<br><br>on: [push]<br><br>jobs:<br>  test:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v2<br>      - name: Use Node.js<br>        uses: actions/setup-node@v2<br>        with:<br>          node-version: &#39;14.x&#39;<br>      - run: npm ci<br>      - run: npx hardhat test</pre><p>Now, every time you push to your repo, your tests will run automatically. No more forgetting to test before that big deploy! 😅</p><h4>Best Practices for Smart Contract Testing</h4><ol><li><strong>Test Edge Cases</strong>: Don’t just test the happy path. What happens when things go wrong?</li><li><strong>Gas Optimization</strong>: Include tests for gas usage to avoid costly surprises.</li><li><strong>Fuzz Testing</strong>: Use tools like Echidna to generate random inputs and find unexpected bugs.</li><li><strong>Simulation</strong>: For complex DeFi protocols, simulate various market conditions.</li></ol><h4>Wrapping Up</h4><p>Setting up automated testing for your smart contracts might seem like a hassle at first, but trust me, it’s worth it. It’ll save you from headaches (and possibly heart attacks) down the line.</p><p>Remember, in the world of Web3, code is law. Make sure your law is air-tight! ⚖️</p><p>Happy testing, and may your contracts always compile on the first try! 🚀</p><p>Want to level up your Web3 QA game even more? Check out <a href="https://web3qa.xyz/">web3qa.xyz</a> for advanced testing strategies and tools specifically designed for blockchain projects. Don’t let bugs be the weak link in your Web3 revolution! 💪🔗</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce9092cd47b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How much does web3 testing really cost? Breaking down the numbers]]></title>
            <link>https://kodziak.medium.com/how-much-does-web3-testing-really-cost-breaking-down-the-numbers-993057febe04?source=rss-ca5cc1972dd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/993057febe04</guid>
            <dc:creator><![CDATA[Przemysław Paczoski]]></dc:creator>
            <pubDate>Thu, 31 Oct 2024 19:02:15 GMT</pubDate>
            <atom:updated>2024-10-31T19:02:15.025Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, we’re gonna crunch some numbers and get real about the costs of testing in the Web3 world. Buckle up, ’cause this might surprise you (and your CFO)!</p><h4>The True Cost of Web3 Testing: It’s Not Just About the Tools 🧰</h4><p>When we talk about Web3 testing costs, it’s easy to focus on the obvious stuff — like test automation tools or fancy blockchain simulators. But let’s be real, the actual expenses go way beyond that. Here’s what you need to consider:</p><ol><li><strong>Smart Contract Audits</strong>: This ain’t your grandma’s code review. Expect to shell out anywhere from $5,000 to $50,000+ depending on complexity.</li><li><strong>Specialized Talent</strong>: Web3 devs and QA engineers don’t come cheap. Annual salaries can easily hit $150,000+.</li><li><strong>Gas Fees</strong>: Yep, even testing costs gas. For complex DApps, this can add up to hundreds or even thousands of dollars per month.</li><li><strong>Infrastructure</strong>: Running nodes, managing testnets — it all adds up. Budget at least a few hundred bucks monthly.</li><li><strong>Security Tools</strong>: Blockchain-specific security scanners can cost $500-$2000 per month.</li></ol><h4>Hidden Costs That’ll Sneak Up On Ya 🕵️‍♂️</h4><p>Here’s where it gets tricky. These sneaky expenses often slip under the radar:</p><ul><li><strong>Learning Curve</strong>: Your team needs time to get up to speed. Factor in at least a month of reduced productivity.</li><li><strong>Blockchain-Specific Bugs</strong>: These can be nasty and time-consuming. Budget extra time for debugging.</li><li><strong>Testnet Instability</strong>: When testnets go down, so does your productivity. Always have a Plan B.</li></ul><h4>Show Me The Code: A Real-World Example 💻</h4><p>Let’s break down a typical test scenario for a DeFi project:</p><pre>describe(&#39;Liquidity Pool&#39;, () =&gt; {<br>  it(&#39;should allow deposits and calculate shares correctly&#39;, async () =&gt; {<br>    const depositAmount = ethers.utils.parseEther(&#39;10&#39;);<br>    await token.approve(pool.address, depositAmount);<br>    await pool.deposit(depositAmount);<br><br>    const userShares = await pool.balanceOf(user.address);<br>    expect(userShares).to.equal(depositAmount);<br>  });<br>});</pre><p>Looks simple, right? But here’s what it actually costs to run:</p><ul><li>Gas fees for approvals and deposits</li><li>Time to set up mock environments</li><li>Potential issues with testnet stability</li></ul><p>All this for just one test! Now multiply that by hundreds of test cases, and you’ll see why proper budgeting is crucial.</p><h4>Strategies to Keep Costs in Check 💰</h4><p>Don’t panic! Here are some pro tips to keep your testing budget from exploding:</p><ol><li><strong>Use Local Blockchain Simulators</strong>: Tools like Ganache can slash your gas fees during development.</li><li><strong>Implement Proper CI/CD</strong>: Catch issues early to save on costly late-stage fixes.</li><li><strong>Prioritize Test Cases</strong>: Focus on critical paths first. Not everything needs 100% coverage.</li><li><strong>Invest in Training</strong>: A skilled team is more efficient and catches issues faster.</li><li><strong>Consider Managed Services</strong>: Sometimes, outsourcing specific testing tasks can be more cost-effective.</li></ol><h4>The Bottom Line: What Should You Budget? 🤔</h4><p>For a mid-sized Web3 project, here’s a rough annual breakdown:</p><ul><li>Smart Contract Audits: $30,000</li><li>QA Team (2 engineers): $300,000</li><li>Tools and Infrastructure: $20,000</li><li>Misc. Expenses (gas, security, etc.): $50,000</li></ul><p><strong>Total: Around $400,000 per year</strong></p><p>Sounds like a lot? Well, consider the alternative — a single major bug could cost you millions in lost funds or reputation damage. Suddenly, that testing budget doesn’t seem so bad, eh?</p><h4>Wrapping Up: The Real Value of Web3 Testing</h4><p>At the end of the day, proper testing isn’t just a cost — it’s an investment in your project’s future. Sure, the numbers might make your accountant sweat, but the peace of mind and user trust you gain? Priceless.</p><p>Remember, in the wild west of Web3, it’s not just about launching fast — it’s about launching right. So budget wisely, test thoroughly, and watch your project thrive! 🚀</p><p>Curious about optimizing your Web3 testing strategy without breaking the bank? Check out <a href="https://web3qa.xyz/">web3qa.xyz</a> for expert insights and cost-effective solutions tailored for the blockchain world. Let’s make your Web3 project bulletproof — without needing a money printer! 💪</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=993057febe04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web2 vs Web3 Testing: Key Differences That Will Surprise You]]></title>
            <link>https://kodziak.medium.com/web2-vs-web3-testing-key-differences-that-will-surprise-you-125f96a97e9f?source=rss-ca5cc1972dd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/125f96a97e9f</guid>
            <dc:creator><![CDATA[Przemysław Paczoski]]></dc:creator>
            <pubDate>Tue, 29 Oct 2024 14:17:59 GMT</pubDate>
            <atom:updated>2024-10-29T14:17:59.102Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey there, fellow testers and Web3 enthusiasts! 👋 Today, we’re diving deep into the world of Web2 vs Web3 testing. Buckle up, ’cause it’s gonna be a wild ride! 🎢</p><h4>The Basics: Web2 vs Web3</h4><p>Before we jump into the testing differences, let’s quickly recap what Web2 and Web3 actually are:</p><ul><li><strong>Web2</strong>: The internet we know and love (or sometimes hate 😅). Centralized, controlled by big tech companies.</li><li><strong>Web3</strong>: The new kid on the block. Decentralized, powered by blockchain, and giving power back to the users.</li></ul><h4>Key Differences in Testing Approaches</h4><h4>1. Environment Setup</h4><p><strong>Web2</strong>: Pretty straightforward. You set up your local environment, maybe a staging server, and you’re good to go.</p><p><strong>Web3</strong>: Oh boy, here’s where things get spicy! 🌶️ You need to set up a local blockchain, deal with test networks (testnets), and sometimes even fork the mainnet. It’s like cooking a gourmet meal instead of microwaving a TV dinner.</p><p>Example:</p><pre>// Web3 local environment setup using Hardhat<br>require(&#39;@nomiclabs/hardhat-waffle&#39;);<br><br>module.exports = {<br>  solidity: &#39;0.8.0&#39;,<br>  networks: {<br>    hardhat: {<br>      forking: {<br>        url: &#39;https://mainnet.infura.io/v3/YOUR-PROJECT-ID&#39;,<br>      },<br>    },<br>  },<br>};</pre><h4>2. State Management</h4><p><strong>Web2</strong>: State is typically managed on the server or in the browser. Resetting state is as easy as clearing a database or local storage.</p><p><strong>Web3</strong>: State lives on the blockchain, my friend! Resetting it means redeploying smart contracts or resetting your local blockchain. It’s like trying to erase your embarrassing high school photos — not impossible, but definitely more complicated. 😅</p><h4>3. Handling Asynchronous Operations</h4><p><strong>Web2</strong>: Async operations are usually related to API calls or database queries.</p><p><strong>Web3</strong>: Welcome to the world of blockchain confirmations! Every transaction needs to be mined and confirmed. It’s like waiting for your crush to text back — sometimes quick, sometimes painfully slow.</p><pre>// Web3 transaction wait<br>const tx = await contract.someFunction();<br>await tx.wait(2); // Wait for 2 block confirmations</pre><h4>4. Security Testing</h4><p><strong>Web2</strong>: Focus on things like XSS, CSRF, SQL injection.</p><p><strong>Web3</strong>: Enter the realm of smart contract vulnerabilities! Reentrancy attacks, front-running, and gas optimization become your new best friends (or worst enemies). It’s like playing chess, but every piece is trying to steal your ETH.</p><h4>5. Performance Testing</h4><p><strong>Web2</strong>: Load testing, stress testing, you know the drill.</p><p><strong>Web3</strong>: Gas optimization becomes crucial. You’re not just testing how many users your app can handle, but how efficiently it uses blockchain resources. It’s like trying to fit your entire wardrobe into a tiny suitcase for a weekend trip.</p><h4>6. User Authentication</h4><p><strong>Web2</strong>: Username/password, OAuth, maybe some 2FA if you’re fancy.</p><p><strong>Web3</strong>: Welcome to the world of wallets and signatures! Users sign transactions with their private keys. It’s like having a unique, cryptographic fingerprint for every action.</p><pre>// Web3 authentication example<br>const message = &#39;Login to MyAwesomeWeb3App&#39;;<br>const signature = await signer.signMessage(message);<br>// Verify signature on the backend</pre><h4>Common Challenges and Solutions</h4><ol><li><strong>Deterministic Testing</strong>:</li></ol><ul><li>Challenge: Blockchain’s inherent randomness makes repeatable tests tricky.</li><li>Solution: Use controlled environments and seed your RNG for deterministic results.</li></ul><ol><li><strong>Long-running Tests</strong>:</li></ol><ul><li>Challenge: Waiting for blockchain confirmations can make tests slow.</li><li>Solution: Use time-travel features in local blockchains to speed things up.</li></ul><ol><li><strong>Gas Costs</strong>:</li></ol><ul><li>Challenge: Tests can get expensive on public testnets.</li><li>Solution: Use local blockchains or forked mainnet for most tests.</li></ul><ol><li><strong>Complex State</strong>:</li></ol><ul><li>Challenge: Blockchain state can be complex and interdependent.</li><li>Solution: Use snapshots to quickly reset to a known state between tests.</li></ul><h4>Conclusion</h4><p>Testing in Web3 is like Web2 testing on steroids. 💪 It’s more complex, more challenging, but also more exciting! As the Web3 space evolves, so do our testing methodologies. Stay curious, keep learning, and most importantly, have fun with it!</p><p>Ready to level up your Web3 testing game? Check out <a href="https://web3qa.xyz/">web3qa.xyz</a> for more in-depth guides, tools, and best practices. Let’s make the decentralized world a better-tested place, one smart contract at a time! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=125f96a97e9f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Load testing types: load, stress, soak, spike. Examples in k6 load testing tool]]></title>
            <link>https://kodziak.medium.com/load-testing-types-load-stress-soak-spike-examples-in-k6-load-testing-tool-962e93c578f3?source=rss-ca5cc1972dd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/962e93c578f3</guid>
            <dc:creator><![CDATA[Przemysław Paczoski]]></dc:creator>
            <pubDate>Fri, 12 Aug 2022 15:27:46 GMT</pubDate>
            <atom:updated>2022-08-12T15:27:46.943Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Originally posted at: <a href="https://kodziak.com/blog/load-testing-types-load-stress-soak-spike">https://kodziak.com/blog/load-testing-types-load-stress-soak-spike</a></blockquote><p>Load testing is a well-known technique of software testing to make sure, that system we’re working on, behaves in a way, we’d like to. During day-to-day tasks, I started thinking if testing the product only from business perspective is enough. Well… No, so I started some research about it.</p><p>I wanted to clarify for myself, what types give me what, as an outcome. What tool should I use, or environment? Do I need to set up something, or just use production? (yeah, jokes aside).</p><p>I’ve tested wrk, jmeter, and k6. At the end, the last one looks as the easiest and most configurable one for me. I’ve created a couple of sample scripts, to show you how to use that tool.</p><p>In the next article, I’ll explain a bit more about environment, and flow how you can set up your load testing.</p><h4>Types of load tests</h4><p>We encounter four types of load tests:</p><ul><li>Load</li><li>Stress</li><li>Soak</li><li>Spike</li></ul><p>Each of them is slightly different, and gives us possibility to check other scenarios/perform quite tests.</p><h4>Load testing</h4><p>Being sure, that the system is meeting the performance goals is one of the things, you should pay attention. This kind of test, is the one, which can provide you this answer.</p><p>This type is concerned with assessing the current performance in terms of concurrent users or requests per second.</p><p><strong>Example code implementation</strong></p><pre>import { sleep } from &quot;k6&quot;;<br><br>import http from &quot;k6/http&quot;;<br><br>export const options = {<br><br>stages: [<br><br>{ duration: &quot;5m&quot;, target: 100 },<br><br>{ duration: &quot;10m&quot;, target: 100 },<br><br>{ duration: &quot;5m&quot;, target: 0 },<br><br>],<br><br>thresholds: {<br><br>http_req_duration: [&quot;p(99)&lt;250&quot;],<br><br>},<br><br>};<br><br>export default function () {<br><br>http.get(&quot;https://httpbin.test.loadimpact.com/&quot;);<br><br>sleep(1); // Make sure, that each user cooldown between requests is 1s<br><br>}</pre><h4>Stress testing</h4><p>The purpose of this type of load test, is to verify the stability and reliability of the system, under extreme condition’s.</p><p>Running this type of load test, will:</p><ul><li>determine behavior of your system under extreme condition’s,</li><li>determine maximum capacity in terms of users throughput,</li><li>determine the breaking point of your system,</li><li>tell you, if your system will recover without manual intervention after the stress test is over.</li></ul><p><strong>Example code implementation</strong></p><pre>import { sleep } from &quot;k6&quot;;<br><br>import http from &quot;k6/http&quot;;<br><br>export const options = {<br><br>stages: [<br><br>{ duration: &quot;2m&quot;, target: 100 },<br><br>{ duration: &quot;5m&quot;, target: 100 },<br><br>{ duration: &quot;2m&quot;, target: 200 },<br><br>{ duration: &quot;5m&quot;, target: 200 },<br><br>{ duration: &quot;2m&quot;, target: 300 },<br><br>{ duration: &quot;5m&quot;, target: 300 },<br><br>{ duration: &quot;2m&quot;, target: 400 },<br><br>{ duration: &quot;5m&quot;, target: 400 },<br><br>{ duration: &quot;10m&quot;, target: 0 },<br><br>],<br><br>};<br><br>export default function () {<br><br>http.get(&quot;https://httpbin.test.loadimpact.com/&quot;);<br><br>sleep(1);<br><br>}</pre><h4>Soak testing</h4><p>The purpose of this type of load test, is to validate the system under long-time overload.</p><p>Running this type of load test, will:</p><ul><li>verify that your system doesn’t suffer from bugs or memory leaks,</li><li>make sure, that your database works under high overload,</li><li>make sure, that your logs works under high overload,</li><li>make sure, that external services you depend on, doesn’t stop under high overload.</li></ul><p>To run them:</p><ul><li>determine the maximum number of users your system can handle,</li><li>get the 80% of that value,</li><li>run the test in three stages: ramp, stay and cooldown.</li></ul><p><strong>Example code implementation</strong></p><pre>import { sleep } from &quot;k6&quot;;<br><br>import http from &quot;k6/http&quot;;<br><br>export const options = {<br><br>stages: [<br><br>{ duration: &quot;5m&quot;, target: 400 },<br><br>{ duration: &quot;3h55m&quot;, target: 400 },<br><br>{ duration: &quot;5m&quot;, target: 0 },<br><br>],<br><br>thresholds: {<br><br>http_req_duration: [&quot;p(99)&lt;250&quot;],<br><br>},<br><br>};<br><br>export default function () {<br><br>http.get(&quot;https://httpbin.test.loadimpact.com/&quot;);<br><br>sleep(1); // Make sure, that each user cooldown between requests is 1s<br><br>}</pre><h4>Spike testing</h4><p>The purpose of this type of load test, is to validate the system under extreme increments and decrements in traffic over a very short time. The main purpose is to evaluate the behaviour of the system to determine recovery time.</p><p>Running this type of load test, will:</p><ul><li>determine how your system will perform under a sudden spikes of traffic,</li><li>determine if your system will recover.</li></ul><p><strong>Example code implementation</strong></p><pre>import { sleep } from &quot;k6&quot;;<br><br>import http from &quot;k6/http&quot;;<br><br>export const options = {<br><br>stages: [<br><br>{ duration: &quot;10s&quot;, target: 100 },<br><br>{ duration: &quot;1m&quot;, target: 100 },<br><br>{ duration: &quot;10s&quot;, target: 1400 },<br><br>{ duration: &quot;3m&quot;, target: 1400 },<br><br>{ duration: &quot;10s&quot;, target: 100 },<br><br>{ duration: &quot;3m&quot;, target: 100 },<br><br>{ duration: &quot;10s&quot;, target: 0 },<br><br>],<br><br>thresholds: {<br><br>http_req_duration: [&quot;p(99)&lt;250&quot;],<br><br>},<br><br>};<br><br>export default function () {<br><br>http.get(&quot;https://httpbin.test.loadimpact.com/&quot;);<br><br>sleep(1); // Make sure, that each user cooldown between requests is 1s<br><br>}</pre><h4>Summary</h4><p>Load testing is a powerful technique to make sure, that your system behaves as expected in various conditions. My personal feeling is that every project should consider them at some point. Getting more, and more clients can make flood the system, and produce terrible feedback, if it can’t handle them.</p><p>k6 seems to be great tool, to set up them fast, clearly with low learning curve.</p><p><strong>Sources</strong></p><ul><li><a href="https://www.youtube.com/watch?v=r-Jte8Y8zag">Getting started with API Load Testing (Stress, Spike, Load, Soak)</a></li><li><a href="https://www.guru99.com/spike-testing.html">What is Spike Testing in Software Testing? Learn With Example</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=962e93c578f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Separate or project repository to store tests? Which, why, and when?]]></title>
            <link>https://kodziak.medium.com/separate-or-project-repository-to-store-tests-which-why-and-when-62784c4f4dbd?source=rss-ca5cc1972dd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/62784c4f4dbd</guid>
            <dc:creator><![CDATA[Przemysław Paczoski]]></dc:creator>
            <pubDate>Mon, 13 Dec 2021 22:51:40 GMT</pubDate>
            <atom:updated>2021-12-13T22:51:40.483Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Originally posted at: <a href="https://kodziak.com/blog/separate-or-project-repository-to-store-tests-which-why-and-when">https://kodziak.com/blog/separate-or-project-repository-to-store-tests-which-why-and-when</a></blockquote><p>While starting to work with end-to-end tests, one of the first questions is where to store them. Alongside source code or in separate repository? Two solutions, both slightly different. Each of the approaches has their pros and cons — but which to choose?</p><p>In this short article, I’ve tried to describe them both. They’re different, and from your perspective you’ve to choose which one to use, which isn’t simple at all. I believe that this could help you a bit.</p><h4>Project repository</h4><p>Store tests alongside source code keeps everything in the same place. You’ve both app-related and tests-related stuff like tasks, workflows etc. in the same spot. It causes, that the developers could execute everything much easier than searching some commands in another repository. It closes the gap between the developers and test engineers (SDET’s). There aren’t any barriers.</p><p>When the tests fail, it would fail on the programmer branch, so it’d be his job to maintain them. That’s the mental shift when things are together. You wouldn’t be responsible for bringing back the tests to love after every failure. Or find the person which going to fix them or the development is blocked.</p><p>The point is, that storing everything in the same repository, there aren’t any other “strange” place where some code checks the developer’s job and makes it easier to maintain.</p><p>What’s more, when the newest feature change the application flow and breaks tests, you don’t have problem with different versions of tests and app. They’re synced because of the same repository. No concern with merges and only one thing which left would be to maintain them on the same branch as the feature is and push a complete working solution. The time when tests aren’t compatible with the newest application version shouldn’t exist.</p><h4>Example structure</h4><pre>//app<br><br>//tests</pre><h4>Separate repository</h4><p>When the test code is in “another” project, and it usually breaks — the developers probably won’t care about it. It’s going to be your job to maintain the tests and unstuck the blocker.</p><p>Unfortunately, when the things are separated, it would reduce the collaboration between team members. If your organization have clear distinction between the developers and test engineers, a separate repository will widen that gap. One wouldn’t work on each other solutions. That’s really not a situation you should go. The most beneficial would be working together on both, the application code and tests, as a team.</p><p>Imagine a situation. From the developer’s perspective. You’ve created a feature which breaks some of them and want’s to merge it, fast. Obvious is, the tests would fail, so you’ve to set up to another repository, maintain the tests and prepare request, or just merge the feature without properly working tests. It would create a gap because it’s impossible to merge both, new versions of the code at the same time.</p><p>In that scenario, each of the repositories going to have workflow according to its needs — which is good. It will separate the contexts, so the person which going to start working on one of the projects will have only things related to that. The application has tasks related to build and running the application, and in tests will contain jobs to set up the application under tests and execute them. But it has downsides too. It’s just annoying to run the whole flow on local machines. You’ll need to execute commands in different places, which bring up the complexity.</p><p>Of course, I didn’t say that only the test’s repository has to contain tests — nah. The application should have their own. The developers should write unit tests alongside the source code and execute them in pipelines.</p><p>Separating the repositories keeps more clean environment. Repositories contain only things it’s concerned about. It’s make easier to navigate on the daily basis. But there’s a downside to this approach. You’ll have more moving parts to your workflow, which makes things more complicated along the way. For example, with new developers, setup everything it’s going to be a little more difficult in front of a situation, where everything is in one place.</p><h4>Example structure</h4><pre>/<br><br>/</pre><h4>Conclusion</h4><h4>Project repository</h4><ul><li>Increase ownership through the team,</li><li>Closes the gap between the developers and test engineers,</li><li>No problem with merging, you’ll always have synced versions between tests and application,</li><li>Everything app and tests related going to be in the same place.</li></ul><h4>Separate repository</h4><ul><li>Decrease ownership through the team,</li><li>Widen the gap between the developers and test engineers,</li><li>Could be a situation where tests aren’t working on newest application version,</li><li>Cleaner environment, only things concerned about are in the repository.</li></ul><p>Reading the article and points above, it seems like a single repository is a straight winner. But it’s just how it works for me, most of the time. It doesn’t mean, that it’s the best solution for your organization. It always depends — on your project architecture, company structure, how many people you have and how you’re working as a test engineers.</p><p>The best would be to talk to your teammates and decide as a team which could work better for you. Work together on that topic. I assumed that you have in-house test engineers. If not, then, probably you should choose a separate repository for the tests.</p><p>Have a nice day! 🥳</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62784c4f4dbd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Six things you should consider while designing a test architecture]]></title>
            <link>https://kodziak.medium.com/six-things-you-should-consider-while-designing-a-test-architecture-9e0873d31abd?source=rss-ca5cc1972dd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e0873d31abd</guid>
            <dc:creator><![CDATA[Przemysław Paczoski]]></dc:creator>
            <pubDate>Tue, 23 Feb 2021 14:19:25 GMT</pubDate>
            <atom:updated>2021-02-23T14:19:25.672Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Originally posted at: <a href="https://kodziak.com/blog/six-things-you-should-consider-while-designing-a-test-architecture">https://kodziak.com/blog/six-things-you-should-consider-while-designing-a-test-architecture</a></blockquote><p>The beginning of automated tests in a project is easy and difficult at the same time. You can start smoothly, using base architecture, simple tests, etc — and it’s gonna work! But… With growing architecture, solutions you’ll take could be very hard to develop in the future.</p><p>That’s why, you should consider a few things, before the start. I want to show you the problems and solutions do they solve.</p><h4>Page Object Model</h4><p>POM — Page Object Model is a design pattern that is commonly used in test automation for avoiding code duplication and improve test maintenance.</p><p>This model contains classes that represent web pages. You break down each page into a corresponded page class. This class contains locators (selectors) to web page elements and methods that perform actions on them.</p><p>This fills the most common actions you’ll be doing in test automation — find the element, fill the value, click the button. For small scripts, you can store selectors in the tests, but with growing suites, you’ll face many duplications — that’s bad, you don’t want them. If one of the used selectors gonna change, you’ll need to update every place, you’ve used it.</p><p>And… POM is the solution. You’ll create a separate class that all of the tests gonna use. Then, if any of the selectors change, you’ll only have to update one place. It’s faster for the person which updates it.</p><p>But… There is another model of creating an architecture for automation tests. It’s called App Actions. I’ve never tested it, so I can’t recommend it, but here’s a nice article about it — <a href="https://www.cypress.io/blog/2019/01/03/stop-using-page-objects-and-start-using-app-actions/">click!</a></p><h4>Logging</h4><p>You should use a logging system to give the user (developer, or tester) enough information about what’s happened in the tests while executing in a relatively short time. It’s most possible, that you’ll run your tests through a remote machine. If they fail, you need to know fast what’s happened. Troubleshoot or reproduce failed tests with a stack trace and the latest assertion message only will be very hard.</p><p>That’s why you should design a logging system.</p><p>A well-designed strategy will show the user step by step, what’s happened in the test. In the project that I’ve worked on, we created a three-step strategy:</p><ul><li>begin,</li><li>info,</li><li>end,</li></ul><p>To do this quickly, we’ve used decorators (TypeScript only).</p><p>For example (code base on puppeteer):</p><pre>@logger<br><br>function getText(selector) {<br><br>return page.$eval(selector, (el) =&gt; el.textContent);<br><br>}</pre><p>Result with:</p><pre>[BEGIN] - getText from: #email<br><br>[INFO] - getText result: sampleemail@gmail.com<br><br>[END] - getText from: #email</pre><p>The assumption was simple. We want to know when the method starts, what’s the result and when ends. We’ve used a method name and parameters as a recognizer. That comes out with well-structured logs, which helps us to know exactly what happened in test execution.</p><p>Also, you can use these logs in your reporting system, which is described below.</p><p>Another good idea to mention is to write custom, detailed assertion messages. For example,</p><pre>Expect: 5, Received: 8</pre><p>It’s saying not much. Without the context and knowledge of what the test is checking, it’s hard to assume what’s happened. You’ll need to check it manually. But…</p><pre>We expect 5 elements on the listing, got 8.</pre><p>It’s easy to read and clearly saying what’s happened. From the message, you can easily assume where’s the problem.</p><p>Also, there are two more areas, where detailed messages could be helpful:</p><ul><li>timeout exceptions — ex. internet connections problem,</li><li>architecture exceptions — ex. DB connection, auth connection problem.</li></ul><p>I believe, that having a proper logging system could make your work easier and speed up the troubleshooting process.</p><h4>Test Data</h4><p>Most common action in your tests gonna be to fill the value within the data. But… You need to have, or generate it. It’s one of the most time-consuming actions, but necessary.</p><p>Let’s split the data into two types:</p><ul><li>static data — the one you store in database/repository/somewhere,</li><li>dynamic data — the one you generate using tools like a faker, etc.</li></ul><p>Using class patterns you can design a system that handles the data for you. Connections to a database or dynamically creating sensitive data (ex. from faker.js).</p><h4>Parallel Executions</h4><p>Parallelization is an automated process that automatically launches your actions simultaneously. The goal is to save execution time by distributing tests across available resources.</p><p>Consider a situation. You have a big database. Execution time takes 50 minutes to complete. You have 50 tests, where one approximately takes 1 minute. Tests are isolated (if not, you need to work on them). Using 5 parallel executions, you can reduce the total testing time to 10 minutes.</p><p>Fast, reliable tests are key to a stable product.</p><p>One, the interesting out-of-the-box solution is <a href="https://knapsackpro.com/">Knapsack Pro</a>. It helps run your tests in a parallel efficient way.</p><h4>Deployment Pipeline</h4><p>A deployment pipeline is a process, where you take the code from version control and make it available for the users in an automated way. The team, which works on a project, needs an efficient way to build, test, and deploy their work to the production environment. In old fashion way, this was a manual process, where there were few deployments per week, now it’s a few per day/hour. A set of automated tools doing it for us.</p><p>Imagine a problem. You have 50 tests and execution takes 50 minutes (without parallel executions). To test the fresh version of the code, the developers need to build an application locally and run the tests against it. And okay, the tests found an issue, so the user fixes the code and does it again. Hours and nervousness growing. I’m pretty sure, that after a few rounds they’re not gonna use the tests. You don’t want this.</p><p>The solution is to use an automated deployment pipeline. It’s designed especially for cases like this.</p><p>Combining it with parallel executions, you will create an efficient, fast strategy, which gonna defend your production with the tests. Even better, if failed tests block the deployment. You’ll never push broken code to the real users. 🥳</p><h4>Reports</h4><p>Reporting is about documenting the process of test execution. They should combine a summary for the management and stakeholders. Also, should be detailed to give the developers feedback. Especially, when something fails.</p><p>Consider a failed execution. Tests are running on a remote machine, and somehow, you need to know what exactly happened. Why they failed and what’s broken. Access to plain logs could be painful in searching this one failed test. A well-created report should cover that.</p><p>Each report could be different, but in my opinion, there are a few must-have metrics:</p><ul><li>machine/environment name,</li><li>total number of running tests,</li><li>duration,</li><li>list of all test cases with logs (steps from logging system) in toggle,</li><li>test result (for every test case).</li></ul><p>Have I mentioned failed test executions and it’s crucial to know what happened? 🥳 Constantly looking at a deployment pipeline dashboard or searching in logs isn’t that efficient. A well-written report, mixed with the slack notification can speed up this process much.</p><h4>Conclusion</h4><p>I’ve described six topics, which are really nice to consider in every mature test automation project. They solve problems, which you’ll encounter on daily basis. By doing some coding and research, you’ll easier your work and make the architecture expandable. Using a few hacks, you’ll speed up your troubleshooting process and with automatically generated reports — you’ll be as transparent as possible with your tests.</p><p>I believe, that this knowledge will help you at the beginning of your journey.</p><p>What’s also good to consider:</p><ul><li>base architecture — pattern to re-use base methods, create browsers,</li><li>video recordings — record whole test session,</li></ul><p>Have a nice day! 🥳</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e0873d31abd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>