forked from sushi-labs/sushiswap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chef Nomi
committed
Aug 23, 2020
0 parents
commit 8426793
Showing
13 changed files
with
1,000 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.sol linguist-language=Solidity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.4.25 <0.7.0; | ||
|
||
library ConvertLib{ | ||
function convert(uint amount,uint conversionRate) public pure returns (uint convertedAmount) | ||
{ | ||
return amount * conversionRate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.4.25 <0.7.0; | ||
|
||
import "./ConvertLib.sol"; | ||
|
||
// This is just a simple example of a coin-like contract. | ||
// It is not standards compatible and cannot be expected to talk to other | ||
// coin/token contracts. If you want to create a standards-compliant | ||
// token, see: https://github.com/ConsenSys/Tokens. Cheers! | ||
|
||
contract MetaCoin { | ||
mapping (address => uint) balances; | ||
|
||
event Transfer(address indexed _from, address indexed _to, uint256 _value); | ||
|
||
constructor() public { | ||
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.4.25 <0.7.0; | ||
|
||
contract Migrations { | ||
address public owner; | ||
uint public last_completed_migration; | ||
|
||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
|
||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const Migrations = artifacts.require("Migrations"); | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(Migrations); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const ConvertLib = artifacts.require("ConvertLib"); | ||
const MetaCoin = artifacts.require("MetaCoin"); | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(ConvertLib); | ||
deployer.link(ConvertLib, MetaCoin); | ||
deployer.deploy(MetaCoin); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "SushiSwap", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@openzeppelin/contracts": "^3.1.0", | ||
"truffle": "^5.1.41" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
pragma solidity >=0.4.25 <0.7.0; | ||
|
||
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"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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'); | ||
}); | ||
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"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = { | ||
// Uncommenting the defaults below | ||
// provides for an easier quick-start with Ganache. | ||
// You can also follow this format for other networks; | ||
// see <http://truffleframework.com/docs/advanced/configuration> | ||
// for more details on how to specify configuration options! | ||
// | ||
//networks: { | ||
// development: { | ||
// host: "127.0.0.1", | ||
// port: 7545, | ||
// network_id: "*" | ||
// }, | ||
// test: { | ||
// host: "127.0.0.1", | ||
// port: 7545, | ||
// network_id: "*" | ||
// } | ||
//} | ||
// | ||
}; |
Oops, something went wrong.