diff --git a/examples/truffle/.gitattributes b/examples/truffle/.gitattributes deleted file mode 100644 index 52031de51..000000000 --- a/examples/truffle/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -*.sol linguist-language=Solidity diff --git a/examples/truffle/.gitignore b/examples/truffle/.gitignore deleted file mode 100644 index b38db2f29..000000000 --- a/examples/truffle/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules/ -build/ diff --git a/examples/truffle/LICENSE b/examples/truffle/LICENSE deleted file mode 100644 index bb98c924b..000000000 --- a/examples/truffle/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2018 Truffle - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - diff --git a/examples/truffle/README.md b/examples/truffle/README.md deleted file mode 100644 index 02103dcf7..000000000 --- a/examples/truffle/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Truffle MetaCoin - -You can diff this project against a `truffle unbox MetaCoin` to see how easy it is to port your dapp to Sapphire. diff --git a/examples/truffle/contracts/ConvertLib.sol b/examples/truffle/contracts/ConvertLib.sol deleted file mode 100644 index c5bb74616..000000000 --- a/examples/truffle/contracts/ConvertLib.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.13; - -// A library is like a contract with reusable code, which can be called by other contracts. -// Deploying common code can reduce gas costs. -library ConvertLib{ - function convert(uint amount, uint conversionRate) public pure returns (uint convertedAmount) - { - return amount * conversionRate; - } -} diff --git a/examples/truffle/contracts/MetaCoin.sol b/examples/truffle/contracts/MetaCoin.sol deleted file mode 100644 index 3fa1cb190..000000000 --- a/examples/truffle/contracts/MetaCoin.sol +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: MIT -// Tells the Solidity compiler to compile only from v0.8.13 to v0.9.0 -pragma solidity ^0.8.13; - -import "./ConvertLib.sol"; - -// This is just a simple example of a coin-like contract. -// It is not ERC20 compatible and cannot be expected to talk to other -// coin/token contracts. - -contract MetaCoin { - mapping (address => uint) balances; - - event Transfer(address indexed _from, address indexed _to, uint256 _value); - - constructor() { - balances[tx.origin] = 10000; - } - - function sendCoin(address receiver, uint amount) public returns(bool sufficient) { - if (balances[msg.sender] < amount) return false; - balances[msg.sender] -= amount; - balances[receiver] += amount; - emit Transfer(msg.sender, receiver, amount); - return true; - } - - function getBalanceInEth(address addr) public view returns(uint){ - return ConvertLib.convert(getBalance(addr),2); - } - - function getBalance(address addr) public view returns(uint) { - return balances[addr]; - } -} diff --git a/examples/truffle/migrations/1_deploy_contracts.js b/examples/truffle/migrations/1_deploy_contracts.js deleted file mode 100644 index 5a77baf42..000000000 --- a/examples/truffle/migrations/1_deploy_contracts.js +++ /dev/null @@ -1,8 +0,0 @@ -const ConvertLib = artifacts.require("ConvertLib"); -const MetaCoin = artifacts.require("MetaCoin"); - -module.exports = function (deployer) { - deployer.deploy(ConvertLib); - deployer.link(ConvertLib, MetaCoin); - deployer.deploy(MetaCoin); -}; diff --git a/examples/truffle/package.json b/examples/truffle/package.json deleted file mode 100644 index 39d183330..000000000 --- a/examples/truffle/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "MetaCoin", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "truffle test" - }, - "keywords": [], - "author": "", - "license": "ISC", - "devDependencies": { - "@truffle/hdwallet-provider": "^2.0.14" - }, - "dependencies": { - "@oasisprotocol/sapphire-paratime": "workspace:^", - "truffle": "^5.6.3" - } -} diff --git a/examples/truffle/scripts/exercise.contract.js b/examples/truffle/scripts/exercise.contract.js deleted file mode 100644 index 2f9e12cb5..000000000 --- a/examples/truffle/scripts/exercise.contract.js +++ /dev/null @@ -1,44 +0,0 @@ -const keccak256 = require("web3").utils.keccak256; - -const MetaCoin = artifacts.require("MetaCoin"); - -async function exerciseContract() { - const mc = await MetaCoin.deployed(); - - const tx = await mc.sendCoin(mc.address, 42); - console.log(`\nSent some coins in ${tx.tx}.`); - const t = tx.logs[0].args; - console.log(`A Transfer(${t[0]}, ${t[0]}, ${t[2].toNumber()}) was emitted.`); - - const storageSlot = await new Promise((resolve, reject) => { - const getStoragePayload = { - method: "eth_getStorageAt", - params: [ - mc.address, - keccak256( - "0x" + "00".repeat(12) + mc.address.slice(2) + "00".repeat(32) - ), - "latest", - ], - jsonrpc: "2.0", - id: "test", - }; - mc.contract.currentProvider.send(getStoragePayload, (err, res) => { - if (err) reject(err); - else resolve(res.result); - }); - }); - console.log(`The balance storage slot contains ${storageSlot}.`); - - const balance = await mc.getBalance(mc.address); - console.log(`The contract now has balance: ${balance.toNumber()}.`); -} - -module.exports = async function (callback) { - try { - await exerciseContract(); - } catch (e) { - console.error(e); - } - callback(); -}; diff --git a/examples/truffle/test/TestMetaCoin.sol b/examples/truffle/test/TestMetaCoin.sol deleted file mode 100644 index 551d81fc0..000000000 --- a/examples/truffle/test/TestMetaCoin.sol +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.13; - -// These files are dynamically created at test time -import "truffle/Assert.sol"; -import "truffle/DeployedAddresses.sol"; -import "../contracts/MetaCoin.sol"; - -contract TestMetaCoin { - - function testInitialBalanceUsingDeployedContract() public { - MetaCoin meta = MetaCoin(DeployedAddresses.MetaCoin()); - - uint expected = 10000; - - Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially"); - } - - function testInitialBalanceWithNewMetaCoin() public { - MetaCoin meta = new MetaCoin(); - - uint expected = 10000; - - Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially"); - } - -} diff --git a/examples/truffle/test/metacoin.js b/examples/truffle/test/metacoin.js deleted file mode 100644 index 245497663..000000000 --- a/examples/truffle/test/metacoin.js +++ /dev/null @@ -1,42 +0,0 @@ -const MetaCoin = artifacts.require("MetaCoin"); - -contract('MetaCoin', (accounts) => { - it('should put 10000 MetaCoin in the first account', async () => { - const metaCoinInstance = await MetaCoin.deployed(); - const balance = await metaCoinInstance.getBalance.call(accounts[0]); - - assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account"); - }); - it('should call a function that depends on a linked library', async () => { - const metaCoinInstance = await MetaCoin.deployed(); - const metaCoinBalance = (await metaCoinInstance.getBalance.call(accounts[0])).toNumber(); - const metaCoinEthBalance = (await metaCoinInstance.getBalanceInEth.call(accounts[0])).toNumber(); - - assert.equal(metaCoinEthBalance, 2 * metaCoinBalance, 'Library function returned unexpected function, linkage may be broken'); - }); - /* - TODO: re-enable after sapphire-dev container in CI has multi-account support - it('should send coin correctly', async () => { - const metaCoinInstance = await MetaCoin.deployed(); - - // Setup 2 accounts. - const accountOne = accounts[0]; - const accountTwo = accounts[1]; - - // Get initial balances of first and second account. - const accountOneStartingBalance = (await metaCoinInstance.getBalance.call(accountOne)).toNumber(); - const accountTwoStartingBalance = (await metaCoinInstance.getBalance.call(accountTwo)).toNumber(); - - // Make transaction from first account to second. - const amount = 10; - await metaCoinInstance.sendCoin(accountTwo, amount, { from: accountOne }); - - // Get balances of first and second account after the transactions. - const accountOneEndingBalance = (await metaCoinInstance.getBalance.call(accountOne)).toNumber(); - const accountTwoEndingBalance = (await metaCoinInstance.getBalance.call(accountTwo)).toNumber(); - - assert.equal(accountOneEndingBalance, accountOneStartingBalance - amount, "Amount wasn't correctly taken from the sender"); - assert.equal(accountTwoEndingBalance, accountTwoStartingBalance + amount, "Amount wasn't correctly sent to the receiver"); - }); - */ -}); diff --git a/examples/truffle/truffle-config.js b/examples/truffle/truffle-config.js deleted file mode 100644 index 7be3e900c..000000000 --- a/examples/truffle/truffle-config.js +++ /dev/null @@ -1,124 +0,0 @@ -/** - * Use this file to configure your truffle project. It's seeded with some - * common settings for different networks and features like migrations, - * compilation and testing. Uncomment the ones you need or modify - * them to suit your project as necessary. - * - * More information about configuration can be found at: - * - * https://trufflesuite.com/docs/truffle/reference/configuration - * - * To deploy via Infura you'll need a wallet provider (like @truffle/hdwallet-provider) - * to sign your transactions before they're sent to a remote public node. Infura accounts - * are available for free at: infura.io/register. - * - * You'll also need a mnemonic - the twelve word phrase the wallet uses to generate - * public/private key pairs. If you're publishing your code to GitHub make sure you load this - * phrase from a file you've .gitignored so it doesn't accidentally become public. - * - */ - -// require('dotenv').config(); -// const mnemonic = process.env["MNEMONIC"]; -// const infuraProjectId = process.env["INFURA_PROJECT_ID"]; - -const HDWalletProvider = require("@truffle/hdwallet-provider"); -const sapphire = require("@oasisprotocol/sapphire-paratime"); - -module.exports = { - /** - * Networks define how you connect to your ethereum client and let you set the - * defaults web3 uses to send transactions. If you don't specify one truffle - * will spin up a development blockchain for you on port 9545 when you - * run `develop` or `test`. You can ask a truffle command to use a specific - * network from the command line, e.g - * - * $ truffle test --network - */ - - networks: { - // Useful for testing. The `development` name is special - truffle uses it by default - // if it's defined here and no other network is specified at the command line. - // You should run a client (like ganache, geth, or parity) in a separate terminal - // tab if you use this network and you must also set the `host`, `port` and `network_id` - // options below to some value. - // - // development: { - // host: "127.0.0.1", // Localhost (default: none) - // port: 8545, // Standard Ethereum port (default: none) - // network_id: "*", // Any network (default: none) - // }, - // - // goerli: { - // provider: () => new HDWalletProvider(mnemonic, `https://goerli.infura.io/v3/${infuraProjectId}`), - // network_id: 5, // Goerli's id - // chain_id: 5 - // } - emerald_mainnet: { - provider: () => - new HDWalletProvider( - [process.env.PRIVATE_KEY], - "https://emerald.oasis.dev" - ), - network_id: 0xa516, - }, - emerald_testnet: { - provider: () => - new HDWalletProvider( - [process.env.PRIVATE_KEY], - "https://testnet.emerald.oasis.dev" - ), - network_id: 0xa515, - }, - emerald_localnet: { - provider: () => - new HDWalletProvider( - [process.env.PRIVATE_KEY], - "http://localhost:8545" - ), - network_id: 0xa514, - }, - sapphire_mainnet: { - provider: () => - sapphire.wrap( - new HDWalletProvider( - [process.env.PRIVATE_KEY], - "https://sapphire.oasis.io" - ) - ), - network_id: 0x5afe, - }, - sapphire_testnet: { - provider: () => - sapphire.wrap( - new HDWalletProvider( - [process.env.PRIVATE_KEY], - "https://testnet.sapphire.oasis.dev" - ) - ), - network_id: 0x5aff, - }, - sapphire_localnet: { - provider: () => - sapphire.wrap( - new HDWalletProvider( - [process.env.PRIVATE_KEY], - "http://localhost:8545" - ) - ), - network_id: 0x5afd, - }, - }, - - // Set default mocha options here, use special reporters etc. - mocha: { - // timeout: 100000 - }, - - // Configure your compilers - compilers: { - solc: { - version: "0.8.13", // Fetch exact version from solc-bin - }, - }, -};