-
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
Showing
5 changed files
with
145 additions
and
163 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 |
---|---|---|
@@ -1,70 +1 @@ | ||
# Getting Started with Create React App | ||
|
||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). | ||
|
||
## Available Scripts | ||
|
||
In the project directory, you can run: | ||
|
||
### `yarn start` | ||
|
||
Runs the app in the development mode.\ | ||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser. | ||
|
||
The page will reload if you make edits.\ | ||
You will also see any lint errors in the console. | ||
|
||
### `yarn test` | ||
|
||
Launches the test runner in the interactive watch mode.\ | ||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. | ||
|
||
### `yarn build` | ||
|
||
Builds the app for production to the `build` folder.\ | ||
It correctly bundles React in production mode and optimizes the build for the best performance. | ||
|
||
The build is minified and the filenames include the hashes.\ | ||
Your app is ready to be deployed! | ||
|
||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. | ||
|
||
### `yarn eject` | ||
|
||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!** | ||
|
||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. | ||
|
||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. | ||
|
||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. | ||
|
||
## Learn More | ||
|
||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). | ||
|
||
To learn React, check out the [React documentation](https://reactjs.org/). | ||
|
||
### Code Splitting | ||
|
||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) | ||
|
||
### Analyzing the Bundle Size | ||
|
||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) | ||
|
||
### Making a Progressive Web App | ||
|
||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) | ||
|
||
### Advanced Configuration | ||
|
||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) | ||
|
||
### Deployment | ||
|
||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) | ||
|
||
### `yarn build` fails to minify | ||
|
||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) | ||
DStock: Decentralised marketplace for Stock Images and Footages. |
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,10 @@ | ||
const DStockToken = artifacts.require("DStockToken"); | ||
const DStock = artifacts.require("DStock"); | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(DStockToken, 1000000).then(function() { | ||
// Token price is 0.001 Ether | ||
var tokenPrice = 1000000000000000; | ||
return deployer.deploy(DStock, DStockToken.address, tokenPrice); | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1 +1,119 @@ | ||
// The test file for DStockToken | ||
var DStockToken = artifacts.require("../contracts/DStockToken.sol"); | ||
|
||
contract('DStockToken', function(accounts) { | ||
var tokenInstance; | ||
|
||
it('initializes the contract with the correct values', function() { | ||
return DStockToken.deployed().then(function(instance) { | ||
tokenInstance = instance; | ||
return tokenInstance.name(); | ||
}).then(function(name) { | ||
assert.equal(name, 'DStock Token', 'has the correct name'); | ||
return tokenInstance.symbol(); | ||
}).then(function(symbol) { | ||
assert.equal(symbol, 'DST', 'has the correct symbol'); | ||
return tokenInstance.standard(); | ||
}).then(function(standard) { | ||
assert.equal(standard, 'DStock Token v1.0', 'has the correct standard'); | ||
}); | ||
}) | ||
|
||
it('allocates the initial supply upon deployment', function() { | ||
return DStockToken.deployed().then(function(instance) { | ||
tokenInstance = instance; | ||
return tokenInstance.totalSupply(); | ||
}).then(function(totalSupply) { | ||
assert.equal(totalSupply.toNumber(), 1000000, 'sets the total supply to 1,000,000'); | ||
return tokenInstance.balanceOf(accounts[0]); | ||
}).then(function(adminBalance) { | ||
assert.equal(adminBalance.toNumber(), 1000000, 'it allocates the initial supply to the admin account'); | ||
}); | ||
}); | ||
|
||
it('transfers token ownership', function() { | ||
return DStockToken.deployed().then(function(instance) { | ||
tokenInstance = instance; | ||
// Test `require` statement first by transferring something larger than the sender's balance | ||
return tokenInstance.transfer.call(accounts[1], 99999999999999999999999); | ||
}).then(assert.fail).catch(function(error) { | ||
assert(error.message.indexOf('revert') >= 0, 'error message must contain revert'); | ||
return tokenInstance.transfer.call(accounts[1], 250000, { from: accounts[0] }); | ||
}).then(function(success) { | ||
assert.equal(success, true, 'it returns true'); | ||
return tokenInstance.transfer(accounts[1], 250000, { from: accounts[0] }); | ||
}).then(function(receipt) { | ||
assert.equal(receipt.logs.length, 1, 'triggers one event'); | ||
assert.equal(receipt.logs[0].event, 'Transfer', 'should be the "Transfer" event'); | ||
assert.equal(receipt.logs[0].args._from, accounts[0], 'logs the account the tokens are transferred from'); | ||
assert.equal(receipt.logs[0].args._to, accounts[1], 'logs the account the tokens are transferred to'); | ||
assert.equal(receipt.logs[0].args._value, 250000, 'logs the transfer amount'); | ||
return tokenInstance.balanceOf(accounts[1]); | ||
}).then(function(balance) { | ||
assert.equal(balance.toNumber(), 250000, 'adds the amount to the receiving account'); | ||
return tokenInstance.balanceOf(accounts[0]); | ||
}).then(function(balance) { | ||
assert.equal(balance.toNumber(), 750000, 'deducts the amount from the sending account'); | ||
}); | ||
}); | ||
|
||
it('approves tokens for delegated transfer', function() { | ||
return DStockToken.deployed().then(function(instance) { | ||
tokenInstance = instance; | ||
return tokenInstance.approve.call(accounts[1], 100); | ||
}).then(function(success) { | ||
assert.equal(success, true, 'it returns true'); | ||
return tokenInstance.approve(accounts[1], 100, { from: accounts[0] }); | ||
}).then(function(receipt) { | ||
assert.equal(receipt.logs.length, 1, 'triggers one event'); | ||
assert.equal(receipt.logs[0].event, 'Approval', 'should be the "Approval" event'); | ||
assert.equal(receipt.logs[0].args._owner, accounts[0], 'logs the account the tokens are authorized by'); | ||
assert.equal(receipt.logs[0].args._spender, accounts[1], 'logs the account the tokens are authorized to'); | ||
assert.equal(receipt.logs[0].args._value, 100, 'logs the transfer amount'); | ||
return tokenInstance.allowance(accounts[0], accounts[1]); | ||
}).then(function(allowance) { | ||
assert.equal(allowance.toNumber(), 100, 'stores the allowance for delegated trasnfer'); | ||
}); | ||
}); | ||
|
||
it('handles delegated token transfers', function() { | ||
return DStockToken.deployed().then(function(instance) { | ||
tokenInstance = instance; | ||
fromAccount = accounts[2]; | ||
toAccount = accounts[3]; | ||
spendingAccount = accounts[4]; | ||
// Transfer some tokens to fromAccount | ||
return tokenInstance.transfer(fromAccount, 100, { from: accounts[0] }); | ||
}).then(function(receipt) { | ||
// Approve spendingAccount to spend 10 tokens form fromAccount | ||
return tokenInstance.approve(spendingAccount, 10, { from: fromAccount }); | ||
}).then(function(receipt) { | ||
// Try transferring something larger than the sender's balance | ||
return tokenInstance.transferFrom(fromAccount, toAccount, 9999, { from: spendingAccount }); | ||
}).then(assert.fail).catch(function(error) { | ||
assert(error.message.indexOf('revert') >= 0, 'cannot transfer value larger than balance'); | ||
// Try transferring something larger than the approved amount | ||
return tokenInstance.transferFrom(fromAccount, toAccount, 20, { from: spendingAccount }); | ||
}).then(assert.fail).catch(function(error) { | ||
assert(error.message.indexOf('revert') >= 0, 'cannot transfer value larger than approved amount'); | ||
return tokenInstance.transferFrom.call(fromAccount, toAccount, 10, { from: spendingAccount }); | ||
}).then(function(success) { | ||
assert.equal(success, true); | ||
return tokenInstance.transferFrom(fromAccount, toAccount, 10, { from: spendingAccount }); | ||
}).then(function(receipt) { | ||
assert.equal(receipt.logs.length, 1, 'triggers one event'); | ||
assert.equal(receipt.logs[0].event, 'Transfer', 'should be the "Transfer" event'); | ||
assert.equal(receipt.logs[0].args._from, fromAccount, 'logs the account the tokens are transferred from'); | ||
assert.equal(receipt.logs[0].args._to, toAccount, 'logs the account the tokens are transferred to'); | ||
assert.equal(receipt.logs[0].args._value, 10, 'logs the transfer amount'); | ||
return tokenInstance.balanceOf(fromAccount); | ||
}).then(function(balance) { | ||
assert.equal(balance.toNumber(), 90, 'deducts the amount from the sending account'); | ||
return tokenInstance.balanceOf(toAccount); | ||
}).then(function(balance) { | ||
assert.equal(balance.toNumber(), 10, 'adds the amount from the receiving account'); | ||
return tokenInstance.allowance(fromAccount, spendingAccount); | ||
}).then(function(allowance) { | ||
assert.equal(allowance.toNumber(), 0, 'deducts the amount from the allowance'); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,96 +1,14 @@ | ||
/** | ||
* 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: | ||
* | ||
* truffleframework.com/docs/advanced/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. | ||
* | ||
*/ | ||
|
||
// const HDWalletProvider = require('@truffle/hdwallet-provider'); | ||
// const infuraKey = "fj4jll3k....."; | ||
// | ||
// const fs = require('fs'); | ||
// const mnemonic = fs.readFileSync(".secret").toString().trim(); | ||
|
||
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 <network-name> | ||
*/ | ||
|
||
// See <http://truffleframework.com/docs/advanced/configuration> | ||
// for more about customizing your Truffle configuration! | ||
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-cli, 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) | ||
// }, | ||
// Another network with more advanced options... | ||
// advanced: { | ||
// port: 8777, // Custom port | ||
// network_id: 1342, // Custom network | ||
// gas: 8500000, // Gas sent with each transaction (default: ~6700000) | ||
// gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei) | ||
// from: <address>, // Account to send txs from (default: accounts[0]) | ||
// websockets: true // Enable EventEmitter interface for web3 (default: false) | ||
// }, | ||
// Useful for deploying to a public network. | ||
// NB: It's important to wrap the provider as a function. | ||
// ropsten: { | ||
// provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`), | ||
// network_id: 3, // Ropsten's id | ||
// gas: 5500000, // Ropsten has a lower block limit than mainnet | ||
// confirmations: 2, // # of confs to wait between deployments. (default: 0) | ||
// timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50) | ||
// skipDryRun: true // Skip dry run before migrations? (default: false for public nets ) | ||
// }, | ||
// Useful for private networks | ||
// private: { | ||
// provider: () => new HDWalletProvider(mnemonic, `https://network.io`), | ||
// network_id: 2111, // This network is yours, in the cloud. | ||
// production: true // Treats this network as if it was a public net. (default: false) | ||
// } | ||
}, | ||
|
||
// Set default mocha options here, use special reporters etc. | ||
mocha: { | ||
// timeout: 100000 | ||
}, | ||
|
||
// Configure your compilers | ||
compilers: { | ||
solc: { | ||
// version: "0.5.1", // Fetch exact version from solc-bin (default: truffle's version) | ||
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false) | ||
// settings: { // See the solidity docs for advice about optimization and evmVersion | ||
// optimizer: { | ||
// enabled: false, | ||
// runs: 200 | ||
// }, | ||
// evmVersion: "byzantium" | ||
// } | ||
development: { | ||
host: "127.0.0.1", | ||
port: 7545, | ||
network_id: "*" // Match any network id | ||
}, | ||
}, | ||
develop: { | ||
port: 8545 | ||
} | ||
} | ||
}; |