{"id":15718545,"url":"https://github.com/dav009/ergo-puppet","last_synced_at":"2025-03-30T22:26:51.417Z","repository":{"id":57732955,"uuid":"458978291","full_name":"dav009/ergo-puppet","owner":"dav009","description":"Unit Testing Ergo Smart contracts offchain ","archived":false,"fork":false,"pushed_at":"2022-02-19T13:40:35.000Z","size":459,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-06T03:32:06.835Z","etag":null,"topics":["blockchain","ergo","scala","testing","unittest","web3"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dav009.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-14T01:28:12.000Z","updated_at":"2022-10-24T18:37:45.000Z","dependencies_parsed_at":"2022-09-26T22:11:12.975Z","dependency_job_id":null,"html_url":"https://github.com/dav009/ergo-puppet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dav009%2Fergo-puppet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dav009%2Fergo-puppet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dav009%2Fergo-puppet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dav009%2Fergo-puppet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dav009","download_url":"https://codeload.github.com/dav009/ergo-puppet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246387875,"owners_count":20769093,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","ergo","scala","testing","unittest","web3"],"created_at":"2024-10-03T21:53:21.043Z","updated_at":"2025-03-30T22:26:51.398Z","avatar_url":"https://github.com/dav009.png","language":"Scala","funding_links":[],"categories":["🛠️ Development Tooling \u003ca id=\"development-tooling\"\u003e\u003c/a\u003e"],"sub_categories":["🧪 Testing \u0026 Debugging \u003ca id=\"testing--debugging\"\u003e\u003c/a\u003e"],"readme":"# Ergo Puppet\n\n![](https://raw.githubusercontent.com/dav009/ergo-puppet/master/puppet.png)\n\nPuppet is an upgrade on the [ergo playground](https://github.com/ergoplatform/ergo-playgrounds). It lets you play and unit test Ergo contracts offchain. Puppet uses as much of AppKit as possible, meaning you should be able to test your code with Puppet with no changes. \n\nPuppet provides you with a dummy `ErgoClient` and a dummy `BlockchainContext`.\n\n## Usage\n\nadd the following dependencies to your `build.sbt`:\n\n```scala\nlibraryDependencies += \"io.github.dav009\" %% \"ergopuppet\" % \"0.0.0+28-8ee0ca24+20220219-2144\"  % Test\nlibraryDependencies += (\"org.scorexfoundation\" %% \"sigma-state\" % \"4.0.5\" ).classifier(\"tests\")\n```\n\n## Simple TX Example\n\n- More examples you can check in the test folder \n- See code snippet below for testing a simple transaction.\n\n```scala\nimport io.github.dav009.ergopuppet.Simulator._\n\n....\n\nval (blockchainSim, ergoClient) = newBlockChainSimulationScenario(\"Simple Tx\")\nergoClient.execute(\n    (ctx: BlockchainContext) =\u003e { \n    \n     // Mocking blockchain state\n      val receiverParty = blockchainSim.newParty(\"receiver\", ctx)\n      val senderParty = blockchainSim.newParty(\"sender\", ctx)\n      senderParty.generateUnspentBoxes(toSpend = 10000000000L)\n      \n      // making a transaction\n      val txBuilder = ctx.newTxBuilder()\n      val amountToSpend: Long = Parameters.OneErg\n      val newBox = txBuilder\n        .outBoxBuilder()\n        .value(amountToSpend)\n        .contract(\n          ctx.compileContract(\n            ConstantsBuilder\n              .create()\n              .item(\"recPk\", receiverParty.wallet.getAddress.asP2PK().pubkey)\n              .build(),\n            \"{ recPk }\"\n          )\n        )\n        .build()\n\n      val boxes = senderParty.wallet.getUnspentBoxes(amountToSpend + Parameters.MinFee).get\n\n      val tx: UnsignedTransaction = txBuilder\n        .boxesToSpend(boxes)\n        .outputs(newBox)\n        .fee(Parameters.MinFee)\n        .sendChangeTo(P2PKAddress(senderParty.wallet.getAddress.getPublicKey()))\n        .build()\n\n      val signed = senderParty.wallet.sign(tx)\n      var receiverUnspentCoins =\n        blockchainSim.getUnspentCoinsFor(receiverParty.wallet.getAddress)\n      assert(receiverUnspentCoins == (0))\n      val txId: String = ctx.sendTransaction(signed)\n      \n      // checking the state of the chain\n      val senderPartyUnspentCoins =\n        blockchainSim.getUnspentCoinsFor(senderParty.wallet.getAddress)\n      receiverUnspentCoins =\n        blockchainSim.getUnspentCoinsFor(receiverParty.wallet.getAddress)\n      assert(\n        senderPartyUnspentCoins == (10000000000L - Parameters.MinFee - amountToSpend)\n      )\n      assert(receiverUnspentCoins == (amountToSpend))\n  }\n)\n....\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdav009%2Fergo-puppet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdav009%2Fergo-puppet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdav009%2Fergo-puppet/lists"}