<?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 Javier Aguirre on Medium]]></title>
        <description><![CDATA[Stories by Javier Aguirre on Medium]]></description>
        <link>https://medium.com/@javaguirre?source=rss-f77efb420f7f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*50jHMfyy_oPP1BUVzkviZg.png</url>
            <title>Stories by Javier Aguirre on Medium</title>
            <link>https://medium.com/@javaguirre?source=rss-f77efb420f7f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 08:31:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@javaguirre/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[CI/CD on a Hyperledger Fabric project]]></title>
            <link>https://medium.com/@javaguirre/ci-cd-on-a-hyperledger-fabric-project-6f05f2b4ea5c?source=rss-f77efb420f7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f05f2b4ea5c</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[hyperledger]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Javier Aguirre]]></dc:creator>
            <pubDate>Mon, 25 Feb 2019 10:45:34 GMT</pubDate>
            <atom:updated>2019-02-25T10:45:34.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*fqTTztbzIUrAZZH3qtupQg.jpeg" /></figure><p>Today we bring you the second post of this series of technical articles regarding development with Hyperledger Fabric. Last time we <a href="https://medium.com/theneonproject/testing-chaincode-on-hyperledger-fabric-22b50a3c1af1">talked about how we test our chaincode</a>, today we go one step further and we’ll show you how we deploy the code automatically.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F26DNdV3b6dqn1jzR6%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F26DNdV3b6dqn1jzR6%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExYm80cDBmZ3MwcHcxMDloaXN0NWx5aTR4NnZvN2kzZTljOXpjN2Z6YiZlcD12MV9naWZzX2dpZklkJmN0PWc%2F26DNdV3b6dqn1jzR6%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/435260ce2a3998af5265320c2c00542f/href">https://medium.com/media/435260ce2a3998af5265320c2c00542f/href</a></iframe><p><strong>CI/CD</strong> is the combined practice of automating the testing of our application and the deployment of the application to our servers.</p><p>Our workflow integrates different platforms in our pipeline, Github, Gitlab CI and IBM Blockchain. We store the code in Github, when we push code to Github it automatically goes to Gitlab CI where the automated tests are executed. If everything goes well we deploy the code to IBM automatically.</p><h4>Continuous Integration</h4><p>Continuous Integration is a practice that requires developers to <strong>integrate</strong> code into a shared repository several times a day. Every time the code is pushed to the code repository, the automated tests are executed.</p><p>There are many cool CI services and we’ve used several of them, right now we’re happy with Gitlab CI, very easy to configure and full of possibilities!</p><p>There are two phases on our CI/CD process: the testing and the deploy phase. You can have several phases in parallel, in the test phase we run three processes, backend, frontend, and chaincode testing. When the tests pass and if the rules are met, the application and chaincode are deployed. :-)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FKsCtl2h2RZKso%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FKsCtl2h2RZKso%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FKsCtl2h2RZKso%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="296" frameborder="0" scrolling="no"><a href="https://medium.com/media/d70216e8ad6e4550821a86287e33c5b8/href">https://medium.com/media/d70216e8ad6e4550821a86287e33c5b8/href</a></iframe><p>Here we’re gonna show you the configuration for the chaincode only since the rest of the application is well documented everywhere (we use industry standards such as Django, React, etc…).</p><p>In the test phase we run the chaincode tests with this configuration, the steps are documented in the code snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b51e3a1e2159e38953cc9ad8b91e545/href">https://medium.com/media/5b51e3a1e2159e38953cc9ad8b91e545/href</a></iframe><h3>Continuous Delivery</h3><p>Every change that passes the automated tests is deployed to production automatically, so when the tests pass it’s time to deploy!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FCDZwopbecAbIc%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FCDZwopbecAbIc%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FCDZwopbecAbIc%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="243" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5bdb62c24265bf7b3b76c84919f5cae/href">https://medium.com/media/a5bdb62c24265bf7b3b76c84919f5cae/href</a></iframe><p>This stage is executed only in two specific cases, for the <strong>staging</strong> and the <strong>production</strong> environment:</p><ul><li><strong>Staging</strong>: When we push the changes to <strong>master</strong> in Git</li><li><strong>Production</strong>: When we push the changes with a Git <strong>tag</strong>. We use the following formats for the tags <em>vYYYY.MM.DD (Year.Month.Day)</em></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4513e1baa062c3ae0504c4b003420e98/href">https://medium.com/media/4513e1baa062c3ae0504c4b003420e98/href</a></iframe><p>Each deploy consists of two API calls. The first one is used to <strong>install the chaincode in the platform</strong>, the second one to <strong>instantiate the chaincode in one of our channels</strong>.</p><p>You can read the <a href="https://blockchain-starter.eu-gb.bluemix.net/api-docs/#/Channels/instantiateChaincode">IBM Blockchain API documentation</a> to know what can you send on these API calls.</p><p>The variables used within Gitlab CI are:</p><ul><li><strong>NETWORK_ID</strong>: network_id in IBM Network credentials</li><li><strong>NETWORK_KEY</strong>: key in IBM Network credentials</li><li><strong>NETWORK_PASS</strong>: secret in IBM Network credentials</li><li><strong>CHANNEL_{ENVIRONMENT}_ID</strong>: the channel is the name we added when we created the channel for this project (<em>defaultchannel</em> by default on IBM Blockchain)</li></ul><p><a href="https://gist.github.com/javaguirre/24130c063131f7c5a0bee1022b4ebdac">See the entire example recipe to CI/CD Hyperledger Fabric on IBM Blockchain</a>.</p><h3>Enter IBM Blockchain</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nZNWqVy-686h54rPUK55Ag.png" /></figure><p>The<strong> IBM Blockchain</strong> platform is, by far, the easiest way we used to build a Hyperledger Fabric network, it has also a nice API to interact with it remotely, it saves a lot of time and pain not needing to administer any of the typical components within a Fabric network. There are only some details we need to take into account when using it:</p><ul><li>When we deploy several smart contracts with the same name it might be difficult to know which is the last one deployed, there is no chaincode grouping by name.</li><li>There is no way of archiving old chaincode release, so we end up with many chaincode versions in the chaincode list.</li><li>There is no way of telling IBM Blockchain that my smart contract, built in Go, has an external dependency.</li><li>Logging is not integrated in the platform, it opens a Kibana dashboard for us to see the logs (I’m not sure if this is good or bad, but the experience is weird).</li></ul><h3>Conclusion</h3><p>Once CI/CD is well configured, creating and instantiating chaincode on IBM Blockchain is a breeze, but there are some caveats we need to overcome to get the most of their platform.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FKINAUcarXNxWE%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FKINAUcarXNxWE%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FKINAUcarXNxWE%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="289" frameborder="0" scrolling="no"><a href="https://medium.com/media/0717d3432003828d62e965c1fe201b5d/href">https://medium.com/media/0717d3432003828d62e965c1fe201b5d/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f05f2b4ea5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing chaincode on Hyperledger Fabric]]></title>
            <link>https://medium.com/@javaguirre/testing-chaincode-on-hyperledger-fabric-22b50a3c1af1?source=rss-f77efb420f7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/22b50a3c1af1</guid>
            <category><![CDATA[continuous-deployment]]></category>
            <category><![CDATA[hyperledger]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Javier Aguirre]]></dc:creator>
            <pubDate>Mon, 21 Jan 2019 16:00:43 GMT</pubDate>
            <atom:updated>2019-01-21T16:00:43.950Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*Y-g8aZO0LSwwJ2BEjciMUQ.jpeg" /></figure><p><a href="https://www.hyperledger.org/">Hyperledger</a> is the Blockchain family of tools and frameworks for permissioned networks. At <a href="http://theneonproject.org/">The Neon Project</a>, we’ve been working on solutions built with <a href="https://www.hyperledger.org/projects/fabric">Hyperledger Fabric</a> for a while now.</p><p>Hyperledger Fabric is a complex system to deploy and it’s important to be careful when we configure certificates, open ports or assign roles, among other things. Luckily there are some good documentation articles from Hyperledger you could read to extend your knowledge if you are interested, such as <a href="https://hyperledger-fabric.readthedocs.io/en/latest/build_network.html">how to build your first network</a> or <a href="https://hyperledger-fabric.readthedocs.io/en/latest/write_first_app.html">writing your first application</a>.</p><p>At The Neon Project, we take pride in making real stuff with Blockchain, working on smart contracts and doing CI/CD on a BDD environment for those contracts.</p><p>Our workflow integrates different platforms in our pipeline: It starts on <em>Github</em>, goes to <em>Gitlab CI</em> and finally deploys the smart contract on the <em>IBM Blockchain</em> platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0xThN67QmQrdTryi_XwCFQ.png" /><figcaption>Gitlab CI pipeline infograph</figcaption></figure><p>Today we want to talk about the first part that makes our development faster, the unit, integration and acceptance tests for the chaincode.</p><h4>Test all the things!</h4><p>At The Neon Project, we have automated testing at our core. <a href="https://en.wikipedia.org/wiki/CI/CD">We apply Continuous Integration and Continuous Delivery</a> in all our projects,<br>so it made sense for us to create a more robust test suite for our chaincode.</p><p>We decided to go with Go, static typing, Go structs and the <a href="https://github.com/hyperledger/fabric-test">examples in the Hyperledger Fabric official repositories</a> made testing easy and straightforward.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FLFmxDLUTQH7dS%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FLFmxDLUTQH7dS%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FLFmxDLUTQH7dS%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="273" frameborder="0" scrolling="no"><a href="https://medium.com/media/483510b2ebb98306166ce53d869aae39/href">https://medium.com/media/483510b2ebb98306166ce53d869aae39/href</a></iframe><p>To make Hyperledger Fabric chaincode easier to test, the developers have created a <a href="https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#NewMockStub">MockStub</a> struct. A <strong>mock</strong> is a service simulating functionality so you don’t call the real one while testing. For example, if we use a service to send SMS, we don’t want our tests to send SMS every time we run them, that’s why we usually use a mock, to simulate we call the method and its response. There are still several commands that <a href="https://github.com/hyperledger/fabric/blob/release-1.4/core/chaincode/shim/mockstub.go#L282-L293">aren’t implemented in the mock needed for some of the MockStub</a>.</p><h4>Run the tests</h4><p>To run the tests locally, we use a <em>Dockerfile</em> that builds our environment. The <strong>Dockerfile</strong> would be something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cffa3ff78cb348d157b99ec3f144ebb/href">https://medium.com/media/6cffa3ff78cb348d157b99ec3f144ebb/href</a></iframe><p>Let’s get into the code above:</p><p>We’re using <strong>Go v1.10 </strong>and<strong> </strong>copying our project code to <strong>/go/src/app</strong>.</p><p>We need to install the dependencies, we’ll use <a href="https://github.com/hyperledger/fabric-sdk-go"><strong>hyperledger/fabric-sdk-go</strong></a>, <a href="https://godoc.org/github.com/pgpst/pgpst/internal/github.com/stretchr/testify/assert"><strong>testify/assert</strong></a> to have a nice way of asserting in our tests and optionally if we do acceptance tests, <a href="https://github.com/DATA-DOG/godog"><strong>cmd/godog</strong></a>.</p><p>We’ll need <strong>libltdl-dev</strong> and install in the Fabric library manually in the <strong>$GOPATH</strong>, it didn’t work for us at the time, but this might be easier with the new version of Fabric.</p><p>We define the path where our chaincode lives (<em>$GOPATH/src/gitlab.com/TheNeonProject/mychaincode</em>) and run the tests with<em> </em><em>go test -v ..</em></p><p>To run this locally we use two commands, one to build the Docker container, and another one to run the tests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3bca7f8868c4dd84f7baf46debba7eb/href">https://medium.com/media/d3bca7f8868c4dd84f7baf46debba7eb/href</a></iframe><p>We’ll get a response like this if everything went nicely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PNwlZKIbNYpxajH2GbcngA.png" /></figure><h4>Code example</h4><p>But talk is cheap, so we’ll show you a code example. :-)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fr056JQBFkE8QE%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fr056JQBFkE8QE%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fr056JQBFkE8QE%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="238" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e1fb091e0d7165b4cd58e12131843a8/href">https://medium.com/media/4e1fb091e0d7165b4cd58e12131843a8/href</a></iframe><p>Here you have a chaincode example with a method getAsset. Read through to see how it looks and we’ll explain right afterwards.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc6413025a5dae330816a935ff7da2f6/href">https://medium.com/media/bc6413025a5dae330816a935ff7da2f6/href</a></iframe><p>This code is for a smart contract with a method <strong>getAsset</strong>.</p><p>The <strong>Invoke</strong> method is the entry point when calling our smart contract via <em>RPC;</em> if the method is not supported it will return an error.<br>That would be a very good initial test to check if our test environment is correctly configured. :-)</p><p>The <strong>getObjectAsBytes</strong> method is just used to return a saved object as a response in the method call.</p><p>So going back to the <strong>getAsset</strong> method, it receives a parameter, which is the ID of the resource and, if it exists, it returns the result as JSON.</p><p>Now you know what the code does, let’s create some tests for this beast, because, as great chefs do, we always need to taste the recipe before serving.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl2YWuhILzuqDcexaw%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl2YWuhILzuqDcexaw%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fl2YWuhILzuqDcexaw%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="184" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bc8aa1920a41eab685d3977e9ab361d/href">https://medium.com/media/8bc8aa1920a41eab685d3977e9ab361d/href</a></iframe><h4>Tests</h4><p>We’re going to <strong>create a test suite with two main test cases</strong>:</p><ul><li>Test when the ID sent doesn’t exist, we’ll assert the error.</li><li>Test when the ID sent does exist, we’ll assert the response is good and an attribute of the object (the name) is present.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f650458cd0e5fb7e1a92b71b671caf0/href">https://medium.com/media/1f650458cd0e5fb7e1a92b71b671caf0/href</a></iframe><p>We follow <a href="http://wiki.c2.com/?ArrangeActAssert">AAA (Arrange Act Asset</a>) principle to see the different parts of the test cases easily. In the different part of the test cases we can see:</p><p>In this case, the <strong>Arrange</strong> would need to initialize the smart contract “connection” and, in case of a valid id, <strong>create the Asset with its name</strong>.</p><p>In the <strong>Act</strong> part of the test, we’ll do mostly the same, use the method name, the ID, and in case of creation or append(edit), the JSON object<br>with the payload.</p><p>In the <strong>Assert</strong> we’ll check if the response is <em>OK or Error</em>, and we can also check with the variables <strong>res.Message</strong> or <strong>res.Payload</strong> if the content<br>of the response is what the right one.</p><p>That’s it for now! In following articles we’ll talk about how to do BDD for the chaincode, data format manipulation for chaincode methods and Continuous Integration / Continuous Deployment for our chaincode on an Hyperledger Fabric network.</p><p>Let us know your comments below and <a href="http://twitter.com/tnpgram">follow us on Twitter</a> to stay tuned!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fch1Z4rUWBZBnO%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fch1Z4rUWBZBnO%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fch1Z4rUWBZBnO%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="233" frameborder="0" scrolling="no"><a href="https://medium.com/media/afd48c13bd83bc57b7af812d84b92a21/href">https://medium.com/media/afd48c13bd83bc57b7af812d84b92a21/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22b50a3c1af1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>