Blockchain & DLT

60Blockchain & DLT (testing-oriented)

What you will master here

  • Blockchain vs DLT — the distinction
  • Bitcoin essentials: transactions, wallets, keys, mining
  • Ethereum: EVM, smart contracts, gas
  • Hyperledger Fabric — permissioned blockchain
  • Token standards: ERC-20, ERC-721 (NFTs), ERC-1155
  • How SDETs test blockchain applications

60.1 Blockchain vs DLT

Distributed Ledger Technology (DLT) = umbrella term: any database replicated across multiple nodes with no central authority. Blockchain = one specific type of DLT where transactions are grouped into blocks, each cryptographically linked to the previous via a hash — forming an immutable chain.

All blockchains are DLTs. Not all DLTs are blockchains (e.g. Hashgraph uses a "DAG" structure instead of blocks).

PropertyBlockchainOther DLT
Data structureLinked blocksDAG, Merkle tree, etc.
ConsensusPoW, PoS, PBFTVaries
ExamplesBitcoin, Ethereum, Hyperledger FabricIOTA (Tangle), Hedera (Hashgraph)

60.2 Core security mechanisms

60.3 Bitcoin — the basics

60.4 Ethereum & the EVM

A tiny smart contract

// Solidity (Java-ish syntax — using java highlighter for clarity)
pragma solidity ^0.8.0;

contract SimpleStorage {
    uint256 private value;
    event ValueChanged(uint256 newValue);

    function set(uint256 newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }
    function get() public view returns (uint256) {
        return value;
    }
}

60.5 Hyperledger Fabric — permissioned blockchain

60.6 Token standards

StandardWhatExamples
ERC-20Fungible tokens — interchangeable unitsUSDT, DAI, most stablecoins, governance tokens
ERC-721Non-fungible tokens (NFTs) — unique itemsArt, collectibles (CryptoPunks, BAYC)
ERC-1155Multi-token (mix of fungible + non-fungible in one contract)Game items, semi-fungible
ERC-4626Tokenised vaultsDeFi yield vaults
ERC-4337Account abstraction (smart wallets)Modern wallet UX

60.7 Cryptocurrencies vs tokens

60.8 What SDETs actually test in blockchain apps

Layer 1: dApp UI (Playwright)

test('connect wallet flow', async ({ page, context }) => {
  /* Inject mock wallet — most teams use a mocked window.ethereum */
  await context.addInitScript(() => {
    (window as any).ethereum = {
      isMetaMask: true,
      request: async ({ method }: any) => {
        if (method === 'eth_requestAccounts') return ['0xAbc...123'];
        if (method === 'eth_chainId') return '0x1';
      },
      on: () => {},
    };
  });
  await page.goto('/');
  await page.getByRole('button', { name: 'Connect Wallet' }).click();
  await expect(page.getByText(/0xAbc...123/)).toBeVisible();
});

Layer 2: Smart contract (Hardhat / Foundry / Truffle)

// Hardhat test (TypeScript)
import { ethers } from 'hardhat';
import { expect } from 'chai';

describe('SimpleStorage', () => {
  it('stores and reads a value', async () => {
    const Factory = await ethers.getContractFactory('SimpleStorage');
    const contract = await Factory.deploy();
    await contract.set(42);
    expect(await contract.get()).to.equal(42);
  });

  it('emits ValueChanged event', async () => {
    const c = await (await ethers.getContractFactory('SimpleStorage')).deploy();
    await expect(c.set(7)).to.emit(c, 'ValueChanged').withArgs(7);
  });
});

Layer 3: Indexer / API

Most dApps run a backend indexer (The Graph, custom) that reads blockchain events and serves a normal REST/GraphQL API. Test that like any API — schema, status codes, latency. Just need a known on-chain state to query against.

60.9 Special challenges

Module 36 — Blockchain Q&A

Blockchain vs DLT?
DLT is the umbrella — any distributed ledger. Blockchain is a specific DLT structure where transactions are grouped into blocks chained by cryptographic hash. Other DLTs use DAGs or other structures.
What's the EVM?
Ethereum Virtual Machine — sandboxed bytecode execution environment that runs smart contracts identically on every Ethereum node. Code compiled (e.g. Solidity → EVM bytecode) and run; deterministic.
ERC-20 vs ERC-721?
ERC-20: fungible tokens (1 USDT = 1 USDT, interchangeable). ERC-721: non-fungible tokens (NFTs) — each token id is unique, not interchangeable.
How would you test a smart contract?
Local devnet (Hardhat / Anvil) for instant block mining. Unit tests in TS via ethers.js + Mocha/Chai or Foundry's Rust-like tests. Cover: state changes, events emitted, gas usage, revert conditions, edge cases. Add invariant tests (Foundry / Echidna) to fuzz inputs.
How would you test a dApp UI?
Playwright with a mocked window.ethereum — inject it via addInitScript. Stub responses to eth_requestAccounts, eth_sendTransaction, etc. Test connect, sign, switch network flows without a real wallet.
What's gas?
A measure of computational effort. Each EVM operation consumes gas. Users pay gas × gas-price (in ETH) to execute. Prevents infinite loops; rewards miners/validators.
Hyperledger Fabric vs Ethereum?
Fabric is permissioned (known participants), uses PBFT consensus, no native token, business-focused. Ethereum is permissionless (anyone can join), uses PoS, has ETH as native currency, focuses on open smart-contract platforms.
What's the difference between a coin and a token?
Coin = native asset of its own blockchain (BTC, ETH). Token = asset issued by a contract on someone else's blockchain (USDT on Ethereum). Tokens depend on the host chain's security.
Why are smart contracts hard to fix?
Once deployed they're immutable. To "fix" you deploy a new version and migrate state. Upgradeable patterns (proxy contracts) exist but add complexity. Hence the emphasis on pre-deploy audits and formal verification.
How does mining differ from staking?
Mining (PoW): nodes solve a hash puzzle; first to solve wins the right to add a block. Energy-intensive. Staking (PoS): validators put tokens as collateral; protocol picks a validator pseudo-randomly weighted by stake. Slashing for misbehaviour. Vastly less energy.
What is forensics on a blockchain?
Tracing money flows across addresses to identify the parties involved. Bitcoin addresses are pseudonymous, not anonymous — every transaction is public. Firms like Chainalysis link addresses to exchanges and (often) to real-world identities.