Code Monkey home page Code Monkey logo

solidity-escrow-arrangement's Introduction

Solidity escrow Arrangement

This repository contains the project source code and dependencies required to deploy a ESCROW ARRANGEMENT in Ethereum.

built-with openzeppelin

1. Description

This project implements a simple escrow arrangement in Ethereum network.

The escrow is deployed with the following 2 Ethereum smart contracts written in solidity:

- BossonCoin.sol

This contract defines the token ('bossonCoin') that is used used witin the escrow arrangement to fund account and execute transactions

BossonCoin.sol inherits the standard ERC20 from OpenZeppelin/ERC20, and is initialy minted with 100 coins.

- BossonEscrow.sol

This contract defines all the 'business logic' of the escrow arrangement.

BossonEscrow.sol inherits the Ownable interface from OpenZeppelin/access/Ownable to ensure that only the escrow agent is allowed to perform changes to the contract state variables, such as balances.

The following functions are implemented on BossonCoin.sol:

Functions Description
Credit() Transfer BossonCoins from Buyer account to BossonEscrow account
Order() Checks Buyer has enough funds on escrow and item availability. Updates internal escrow balances for Buyer and Seller according to item price. Marks item state as AWAITING_DELIVERY
Offer() Creates a new item for sale and adds it to the BossonScrow stock of items for sale. Marks item state as OFFERED
Complete() Transfer BossonCoins from BossonEscrow account to Seller account. Updates item ownership to Buyer. Marks item state as COMPLETE
Complain() Reverts internal escrow balances for Buyer and Seller account according to item price. Marks item state as OFFERED

2. Framework and dependencies

  • Source code language: Solidity
  • Development environment: Node.js / NPM / Truffle / Ganache
  • Testing: Truffle / Mocha / Chai

3. How it all fits together

- Initial mint

mintin

- Example flow for trasaction: credit(buyer1, 20)

credit(buyer1,20)

- Example flow for trasaction: order(buyer1, "T-shirt")

order(buyer1, "T-shirt")

- Example flow for trasaction: confirm(buyer1, "T-shirt")

confirm(buyer1, "T-shirt")

4. Install

Clone repository and install dependencies and devDependencies:

$ npm install -g truffle
$ npm install -g ganache-cli
$ cd bossonEscrow
$ npm init

5. Usage

Start ganache-cli development ethereum network:

$ ganache-cli -d 10000000 --allowUnlimitedContractSize --gasLimit=0x1FFFFFFFF

On another terminal, compile and deploy solidity contracts to Ganache development network:

$ truffle compile
$ truffle migrate

6. Test

The problem example input provided in the technical assignment is coded within the truffle test file BossonEscrow.assigmentTest.js:

       //execute example input TXs
        await _bossoncoin.approve(_bossonescrow.address, tokens('20'), {from: buyer1})
        await _bossonescrow.credit(buyer1, tokens('20'), {from: escrowAgent})
        await _bossoncoin.approve(_bossonescrow.address, tokens('40'), {from: buyer2})
        await _bossonescrow.credit(buyer2, tokens('40'), {from: escrowAgent})
        await _bossonescrow.offer(seller1, "Coffee", tokens('3'), 10)
        await _bossonescrow.offer(seller2, "T-shirt", tokens('5'), 10)
        await _bossonescrow.offer(seller1, "Tea", tokens('2.5'), 10)
        await _bossonescrow.offer(seller1, "Cake", tokens('3.5'), 10)
        await _bossonescrow.offer(seller2, "Shorts", tokens('8'), 10)
        await _bossonescrow.offer(seller2, "Hoody", tokens('12'), 10)
        await _bossonescrow.order(buyer1, "T-shirt", {from: escrowAgent})
        await _bossoncoin.approve(_bossonescrow.address, tokens('10'), {from: buyer1})
        await _bossonescrow.credit(buyer1, tokens('10'), {from: escrowAgent})
        await _bossonescrow.order(buyer2, "Hoody", {from: escrowAgent})
        await _bossonescrow.complete(buyer1, "T-shirt", {from: escrowAgent})
        await _bossonescrow.order(buyer1, "Coffee", {from: escrowAgent})
        await _bossonescrow.order(buyer1, "Cake", {from: escrowAgent})
        await _bossonescrow.complain(buyer2, "Hoody", {from: escrowAgent})
        await _bossonescrow.order(buyer2, "Tea", {from: escrowAgent})
        await _bossonescrow.complete(buyer1, "Coffee", {from: escrowAgent})
  • Expected flow of coins and balance state as per example input:

Excel

  • Execute truffle test from command prompt:
$ truffle test
  • Expected output:
  Contract: bosson escrow arrangement
    Bosson escrow assigment


         (test console output) Balance buyer1: 18.5
      ✓ Buyer1 balance is 18.5 (106ms)
         (test console output) Balance Seller2: 5
      ✓ Seller2 balance is 5 (101ms)
         (test console output) Escrow internal balance: 62
         (test console output) BossonCoin Escrow account balance:62
      ✓ Escrow balance is 62 (193ms)


  3 passing (6s)

solidity-escrow-arrangement's People

Contributors

alejoacosta74 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.