diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..00fd3950 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..723ef36f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/build/contracts/Crowdsale.json b/build/contracts/Crowdsale.json new file mode 100644 index 00000000..7634f93c --- /dev/null +++ b/build/contracts/Crowdsale.json @@ -0,0 +1,283 @@ +{ + "contract_name": "Crowdsale", + "abi": [ + { + "constant": true, + "inputs": [], + "name": "creator", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "withdrawFunds", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "amount", + "type": "uint256" + } + ], + "name": "refund", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "exchangeRate", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "amount", + "type": "uint256" + } + ], + "name": "burn", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "currentBalence", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "amount", + "type": "uint256" + } + ], + "name": "mint", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalRaised", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "queue", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "deliver", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": true, + "type": "function" + }, + { + "inputs": [ + { + "name": "_exhangeRate", + "type": "uint256" + }, + { + "name": "_totalSupply", + "type": "uint256" + }, + { + "name": "_timeInMinutesForFundraising", + "type": "uint256" + } + ], + "payable": false, + "type": "constructor" + }, + { + "payable": false, + "type": "fallback" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "name": "status", + "type": "bool" + } + ], + "name": "TokenDelivered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "name": "status", + "type": "bool" + } + ], + "name": "EtherRefunded", + "type": "event" + } + ], + "unlinked_binary": "0x6060604052341561000f57600080fd5b6040516060806115568339810160405280805191906020018051919060200180519150505b426003819055603c82020160045560008054600160a060020a03191633600160a060020a031617905560058390558161006b6100f6565b908152602001604051809103906000f080151561008757600080fd5b60068054600160a060020a031916600160a060020a039290921691909117905560646100b1610106565b908152602001604051809103906000f08015156100cd57600080fd5b60078054600160a060020a031916600160a060020a03929092169190911790555b505050610116565b60405161066380610a5383390190565b6040516104a0806110b683390190565b61092e806101256000396000f300606060405236156100885763ffffffff60e060020a60003504166302d05d3f811461009b57806324600fc3146100ca578063278ecde1146100f15780633ba0b9a91461011b57806342966c681461014057806384b2142b14610158578063a0712d681461017d578063c5c4744c14610195578063e10d29ee146101ba578063fd3e50a7146101e9575b341561009357600080fd5b5b600080fd5b005b34156100a657600080fd5b6100ae610205565b604051600160a060020a03909116815260200160405180910390f35b34156100d557600080fd5b6100dd610214565b604051901515815260200160405180910390f35b34156100fc57600080fd5b6100dd600435610275565b604051901515815260200160405180910390f35b341561012657600080fd5b61012e610395565b60405190815260200160405180910390f35b341561014b57600080fd5b61009960043561039b565b005b341561016357600080fd5b61012e610417565b60405190815260200160405180910390f35b341561018857600080fd5b61009960043561041d565b005b34156101a057600080fd5b61012e610499565b60405190815260200160405180910390f35b34156101c557600080fd5b6100ae61049f565b604051600160a060020a03909116815260200160405180910390f35b6100dd6104ae565b604051901515815260200160405180910390f35b600054600160a060020a031681565b600454600090421161022557600080fd5b60005433600160a060020a0390811691161461024057600080fd5b600054600254600160a060020a039091169080156108fc0290604051600060405180830381858888f19450505050505b5b5b90565b6000804260035410801561028a575060045442105b151561029557600080fd5b600654600160a060020a031663410085df338560006040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b15156102f457600080fd5b6102c65a03f1151561030557600080fd5b505050604051805191505080156103445733600160a060020a03166108fc60055485029081150290604051600060405180830381858888f19450505050505b7ff252967651cc00909ef5a4a48ce7be5929b85746b9d3d022c4bd8900a1ab1f243382604051600160a060020a039092168252151560208201526040908101905180910390a18091505b5b50919050565b60055481565b60005433600160a060020a039081169116146103b657600080fd5b600654600160a060020a03166342966c688260405160e060020a63ffffffff84160281526004810191909152602401600060405180830381600087803b15156103fe57600080fd5b6102c65a03f1151561040f57600080fd5b5050505b5b50565b60025481565b60005433600160a060020a0390811691161461043857600080fd5b600654600160a060020a031663a0712d688260405160e060020a63ffffffff84160281526004810191909152602401600060405180830381600087803b15156103fe57600080fd5b6102c65a03f1151561040f57600080fd5b5050505b5b50565b60015481565b600754600160a060020a031681565b6000806000426003541080156104c5575060045442105b15156104d057600080fd5b60055460015460065434909202935090600160a060020a03166318160ddd6000604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b151561052557600080fd5b6102c65a03f1151561053657600080fd5b505050604051805190500382111561054d57600080fd5b600754600160a060020a0316638f807f6b3360405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401600060405180830381600087803b151561059d57600080fd5b6102c65a03f115156105ae57600080fd5b5050505b600754600190600160a060020a031663ad7d59fc6000604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b15156105fd57600080fd5b6102c65a03f1151561060e57600080fd5b5050506040518051905060ff161115610626576105b2565b600754600160a060020a031663ad7d59fc6000604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b151561066e57600080fd5b6102c65a03f1151561067f57600080fd5b5050506040518051905060ff16600114151561069a57600080fd5b600754600160a060020a031663e0c6190d6040518163ffffffff1660e060020a028152600401600060405180830381600087803b15156106d957600080fd5b6102c65a03f115156106ea57600080fd5b5050600754600160a060020a0316905063ad7d59fc6000604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b151561073657600080fd5b6102c65a03f1151561074757600080fd5b505050604051805160ff161515905061075f57600080fd5b5b600754600190600160a060020a0316633e3c9eae6000604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b15156107ab57600080fd5b6102c65a03f115156107bc57600080fd5b5050506040518051905060ff1610156107d45761075f565b600754600160a060020a031663957908d16040518163ffffffff1660e060020a028152600401600060405180830381600087803b151561081357600080fd5b6102c65a03f1151561082457600080fd5b5050600654600160a060020a0316905063a9059cbb338460006040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b151561088757600080fd5b6102c65a03f1151561089857600080fd5b505050604051805191505080156108b25760028054340190555b7f41c2f4225ceb1479771ee59967887abb5a42980e43535172ca3445699dbeebbf3382604051600160a060020a039092168252151560208201526040908101905180910390a18092505b5b5050905600a165627a7a72305820aca5fb09318b1d059941b23fc9631ee98af57e7bb2ca3eaddbaa8cd9cf0f645900296060604052341561000f57600080fd5b604051602080610663833981016040528080519150505b60008190555b505b6106268061003d6000396000f300606060405236156100965763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461009b57806318160ddd146100d157806323b872dd146100f6578063410085df1461013257806342966c681461016857806370a0823114610180578063a0712d68146101b1578063a9059cbb146101c9578063dd62ed3e146101ff575b600080fd5b34156100a657600080fd5b6100bd600160a060020a0360043516602435610236565b604051901515815260200160405180910390f35b34156100dc57600080fd5b6100e46102a6565b60405190815260200160405180910390f35b341561010157600080fd5b6100bd600160a060020a03600435811690602435166044356102ac565b604051901515815260200160405180910390f35b341561013d57600080fd5b6100bd600160a060020a0360043516602435610433565b604051901515815260200160405180910390f35b341561017357600080fd5b61017e600435610498565b005b341561018b57600080fd5b6100e4600160a060020a03600435166104d8565b60405190815260200160405180910390f35b34156101bc57600080fd5b61017e6004356104f7565b005b34156101d457600080fd5b6100bd600160a060020a0360043516602435610503565b604051901515815260200160405180910390f35b341561020a57600080fd5b6100e4600160a060020a03600435811690602435166105cd565b60405190815260200160405180910390f35b600160a060020a03338116600081815260026020908152604080832094871680845294909152808220805486019055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a35060015b92915050565b60005481565b600160a060020a0383166000908152600160205260408120548290108015906102d55750600082115b80156102fa5750600160a060020a038316600090815260016020526040902054828101115b156104275783600160a060020a031633600160a060020a0316141561038657600160a060020a038085166000818152600160205260408082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a350600161042b565b8161039185336105cd565b1161042157600160a060020a038085166000818152600260209081526040808320338616845282528083208054889003905583835260019091528082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a350600161042b565b5b61042b565b5060005b5b9392505050565b600160a060020a03821660009081526001602052604081205482901080159061045c5750600082115b156104895750600160a060020a0382166000908152600160208190526040909120805483900390556102a0565b5060006102a0565b5b92915050565b6000805482900390557fb90306ad06b2a6ff86ddc9327db583062895ef6540e62dc50add009db5b356eb8160405190815260200160405180910390a15b50565b600160a060020a0381166000908152600160205260409020545b919050565b60008054820190555b50565b600160a060020a03331660009081526001602052604081205482901080159061052c5750600082115b80156105515750600160a060020a038316600090815260016020526040902054828101115b156105c357600160a060020a033381166000818152600160205260408082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060016102a0565b5060005b92915050565b600160a060020a038083166000908152600260209081526040808320938516835292905220545b929150505600a165627a7a723058203bd278523b029ba6358fece3218519618710b8378b0b83fe7130f3c54585a8c2002960606040526000805460ff19166005179055341561001c57600080fd5b6040516020806104a0833981016040528080519150505b6002805460ff1916905560018190555b505b61044c806100546000396000f300606060405236156100805763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631e22314381146100855780633e3c9eae146100b45780638f807f6b146100dd578063957908d1146100fe578063ad7d59fc14610113578063e0c6190d1461013c578063f2a75fe414610151575b600080fd5b341561009057600080fd5b610098610178565b604051600160a060020a03909116815260200160405180910390f35b34156100bf57600080fd5b6100c76101c2565b60405160ff909116815260200160405180910390f35b34156100e857600080fd5b6100fc600160a060020a03600435166101cc565b005b341561010957600080fd5b6100fc610278565b005b341561011e57600080fd5b6100c76102e7565b60405160ff909116815260200160405180910390f35b341561014757600080fd5b6100fc610354565b005b341561015c57600080fd5b6101646103a4565b604051901515815260200160405180910390f35b60025460009060ff16819011156101bb5760038054600090811061019857fe5b906000526020600020906002020160005b5054600160a060020a031690506101bf565b5060005b90565b60025460ff165b90565b60005460025460ff9182169116106101e357600080fd5b60038054600181016101f583826103af565b916000526020600020906002020160005b60408051908101604052600160a060020a03851681524260208201529190508151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a039190911617815560208201516001918201556002805460ff19811660ff9182169093011691909117905550505b50565b600254600060ff90911611156102e45760038054600090811061029757fe5b906000526020600020906002020160005b50805473ffffffffffffffffffffffffffffffffffffffff1916815560006001909101556002805460ff808216600019011660ff199091161790555b5b565b6000805b60025460ff908116908216101561034b5733600160a060020a031660038260ff1681548110151561031857fe5b906000526020600020906002020160005b5054600160a060020a0316141561034257809150610350565b5b6001016102eb565b600091505b5090565b600254600060ff9091161180156103935750426001546003600081548110151561037a57fe5b906000526020600020906002020160005b506001015401105b156102e4576102e4610278565b5b5b565b60025460ff16155b90565b8154818355818115116103db576002028160020283600052602060002091820191016103db91906103e1565b5b505050565b6101bf91905b8082111561035057805473ffffffffffffffffffffffffffffffffffffffff19168155600060018201556002016103e7565b5090565b905600a165627a7a72305820f5706623c3ea06a14b7c3d6b40fe3ac5596bec4e716bca83a051c0113bf66a690029", + "networks": { + "1509327668930": { + "events": { + "0x41c2f4225ceb1479771ee59967887abb5a42980e43535172ca3445699dbeebbf": { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "name": "status", + "type": "bool" + } + ], + "name": "TokenDelivered", + "type": "event" + }, + "0xf252967651cc00909ef5a4a48ce7be5929b85746b9d3d022c4bd8900a1ab1f24": { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "name": "status", + "type": "bool" + } + ], + "name": "EtherRefunded", + "type": "event" + } + }, + "links": {}, + "address": "0x54c1bf462bd6ad80f2ec63784ec35759e66ecba3", + "updated_at": 1509327705376 + }, + "1509337117897": { + "events": { + "0x41c2f4225ceb1479771ee59967887abb5a42980e43535172ca3445699dbeebbf": { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "name": "status", + "type": "bool" + } + ], + "name": "TokenDelivered", + "type": "event" + }, + "0xf252967651cc00909ef5a4a48ce7be5929b85746b9d3d022c4bd8900a1ab1f24": { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "name": "status", + "type": "bool" + } + ], + "name": "EtherRefunded", + "type": "event" + } + }, + "links": {}, + "address": "0x29fdc7fa8b7bed0a26ec624c5a7a2319da6be0d0", + "updated_at": 1509337129588 + } + }, + "schema_version": "0.0.5", + "updated_at": 1509337129588 +} \ No newline at end of file diff --git a/build/contracts/ERC20Interface.json b/build/contracts/ERC20Interface.json new file mode 100644 index 00000000..438c2d38 --- /dev/null +++ b/build/contracts/ERC20Interface.json @@ -0,0 +1,176 @@ +{ + "contract_name": "ERC20Interface", + "abi": [ + { + "constant": false, + "inputs": [ + { + "name": "_spender", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_from", + "type": "address" + }, + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_owner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "name": "balance", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_owner", + "type": "address" + }, + { + "name": "_spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "name": "remaining", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "_from", + "type": "address" + }, + { + "indexed": true, + "name": "_to", + "type": "address" + }, + { + "indexed": false, + "name": "_value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "_owner", + "type": "address" + }, + { + "indexed": true, + "name": "_spender", + "type": "address" + }, + { + "indexed": false, + "name": "_value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + } + ], + "unlinked_binary": "0x", + "networks": {}, + "schema_version": "0.0.5", + "updated_at": 1509337110556 +} \ No newline at end of file diff --git a/build/contracts/Math.json b/build/contracts/Math.json new file mode 100644 index 00000000..50c22c66 --- /dev/null +++ b/build/contracts/Math.json @@ -0,0 +1,8 @@ +{ + "contract_name": "Math", + "abi": [], + "unlinked_binary": "0x60606040523415600e57600080fd5b5b603680601c6000396000f30060606040525b600080fd00a165627a7a72305820eb855728139403df615f8e482c318da4945731be87bdeb0e632e84f60ec384f20029", + "networks": {}, + "schema_version": "0.0.5", + "updated_at": 1509327704464 +} \ No newline at end of file diff --git a/build/contracts/Migrations.json b/build/contracts/Migrations.json new file mode 100644 index 00000000..61d52701 --- /dev/null +++ b/build/contracts/Migrations.json @@ -0,0 +1,79 @@ +{ + "contract_name": "Migrations", + "abi": [ + { + "constant": false, + "inputs": [ + { + "name": "new_address", + "type": "address" + } + ], + "name": "upgrade", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "last_completed_migration", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "completed", + "type": "uint256" + } + ], + "name": "setCompleted", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "inputs": [], + "payable": false, + "type": "constructor" + } + ], + "unlinked_binary": "0x6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b6101e58061003c6000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630900f010811461005e578063445df0ac1461007f5780638da5cb5b146100a4578063fdacd576146100d3575b600080fd5b341561006957600080fd5b61007d600160a060020a03600435166100eb565b005b341561008a57600080fd5b610092610182565b60405190815260200160405180910390f35b34156100af57600080fd5b6100b7610188565b604051600160a060020a03909116815260200160405180910390f35b34156100de57600080fd5b61007d600435610197565b005b6000805433600160a060020a039081169116141561017c5781905080600160a060020a031663fdacd5766001546040517c010000000000000000000000000000000000000000000000000000000063ffffffff84160281526004810191909152602401600060405180830381600087803b151561016757600080fd5b6102c65a03f1151561017857600080fd5b5050505b5b5b5050565b60015481565b600054600160a060020a031681565b60005433600160a060020a03908116911614156101b45760018190555b5b5b505600a165627a7a72305820fa6c296ebecbcd435b3e1a79ab91aeceb41aeae9d1a346db95530ee00a20c6a80029", + "networks": { + "1509327668930": { + "events": {}, + "links": {}, + "address": "0x4ab54ed565a537e0495552c05a5700c255bfe68f", + "updated_at": 1509327705382 + }, + "1509337117897": { + "events": {}, + "links": {}, + "address": "0x2772684b8a88b4c1d7c02e70bf1fe1e06c551b40", + "updated_at": 1509337129593 + } + }, + "schema_version": "0.0.5", + "updated_at": 1509337129593 +} \ No newline at end of file diff --git a/build/contracts/Queue.json b/build/contracts/Queue.json new file mode 100644 index 00000000..061512ef --- /dev/null +++ b/build/contracts/Queue.json @@ -0,0 +1,113 @@ +{ + "contract_name": "Queue", + "abi": [ + { + "constant": true, + "inputs": [], + "name": "getFirst", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "qsize", + "outputs": [ + { + "name": "", + "type": "uint8" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "addr", + "type": "address" + } + ], + "name": "enqueue", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "dequeue", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "checkPlace", + "outputs": [ + { + "name": "", + "type": "uint8" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "checkTime", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "empty", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "type": "function" + }, + { + "inputs": [ + { + "name": "_timeLimit", + "type": "uint256" + } + ], + "payable": false, + "type": "constructor" + } + ], + "unlinked_binary": "0x60606040526000805460ff19166005179055341561001c57600080fd5b6040516020806104a0833981016040528080519150505b6002805460ff1916905560018190555b505b61044c806100546000396000f300606060405236156100805763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631e22314381146100855780633e3c9eae146100b45780638f807f6b146100dd578063957908d1146100fe578063ad7d59fc14610113578063e0c6190d1461013c578063f2a75fe414610151575b600080fd5b341561009057600080fd5b610098610178565b604051600160a060020a03909116815260200160405180910390f35b34156100bf57600080fd5b6100c76101c2565b60405160ff909116815260200160405180910390f35b34156100e857600080fd5b6100fc600160a060020a03600435166101cc565b005b341561010957600080fd5b6100fc610278565b005b341561011e57600080fd5b6100c76102e7565b60405160ff909116815260200160405180910390f35b341561014757600080fd5b6100fc610354565b005b341561015c57600080fd5b6101646103a4565b604051901515815260200160405180910390f35b60025460009060ff16819011156101bb5760038054600090811061019857fe5b906000526020600020906002020160005b5054600160a060020a031690506101bf565b5060005b90565b60025460ff165b90565b60005460025460ff9182169116106101e357600080fd5b60038054600181016101f583826103af565b916000526020600020906002020160005b60408051908101604052600160a060020a03851681524260208201529190508151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a039190911617815560208201516001918201556002805460ff19811660ff9182169093011691909117905550505b50565b600254600060ff90911611156102e45760038054600090811061029757fe5b906000526020600020906002020160005b50805473ffffffffffffffffffffffffffffffffffffffff1916815560006001909101556002805460ff808216600019011660ff199091161790555b5b565b6000805b60025460ff908116908216101561034b5733600160a060020a031660038260ff1681548110151561031857fe5b906000526020600020906002020160005b5054600160a060020a0316141561034257809150610350565b5b6001016102eb565b600091505b5090565b600254600060ff9091161180156103935750426001546003600081548110151561037a57fe5b906000526020600020906002020160005b506001015401105b156102e4576102e4610278565b5b5b565b60025460ff16155b90565b8154818355818115116103db576002028160020283600052602060002091820191016103db91906103e1565b5b505050565b6101bf91905b8082111561035057805473ffffffffffffffffffffffffffffffffffffffff19168155600060018201556002016103e7565b5090565b905600a165627a7a72305820f5706623c3ea06a14b7c3d6b40fe3ac5596bec4e716bca83a051c0113bf66a690029", + "networks": { + "1509327668930": { + "events": {}, + "links": {}, + "address": "0xe3b08d118fdb4f6d5afceb5be95df1e44440e762", + "updated_at": 1509327705379 + }, + "1509337117897": { + "events": {}, + "links": {}, + "address": "0x0e14928a4e352bca36bc683b5a9465a6c77454db", + "updated_at": 1509337129592 + } + }, + "schema_version": "0.0.5", + "updated_at": 1509337129592 +} \ No newline at end of file diff --git a/build/contracts/SafeMath.json b/build/contracts/SafeMath.json new file mode 100644 index 00000000..047a9c4f --- /dev/null +++ b/build/contracts/SafeMath.json @@ -0,0 +1,8 @@ +{ + "contract_name": "SafeMath", + "abi": [], + "unlinked_binary": "0x60606040523415600e57600080fd5b5b603680601c6000396000f30060606040525b600080fd00a165627a7a723058206253a4a0942398dc417fdfc4a5f89e1806e15f4b38fac8b691b39e81ea2622bf0029", + "networks": {}, + "schema_version": "0.0.5", + "updated_at": 1509327704464 +} \ No newline at end of file diff --git a/build/contracts/Token.json b/build/contracts/Token.json new file mode 100644 index 00000000..28dfc025 --- /dev/null +++ b/build/contracts/Token.json @@ -0,0 +1,373 @@ +{ + "contract_name": "Token", + "abi": [ + { + "constant": false, + "inputs": [ + { + "name": "_spender", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_from", + "type": "address" + }, + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_from", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "refund", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_amount", + "type": "uint256" + } + ], + "name": "burn", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_owner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "name": "balance", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_amount", + "type": "uint256" + } + ], + "name": "mint", + "outputs": [], + "payable": false, + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "_owner", + "type": "address" + }, + { + "name": "_spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "name": "remaining", + "type": "uint256" + } + ], + "payable": false, + "type": "function" + }, + { + "inputs": [ + { + "name": "_totalSupplyAmount", + "type": "uint256" + } + ], + "payable": false, + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "_from", + "type": "address" + }, + { + "indexed": true, + "name": "_to", + "type": "address" + }, + { + "indexed": false, + "name": "_value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "_owner", + "type": "address" + }, + { + "indexed": true, + "name": "_spender", + "type": "address" + }, + { + "indexed": false, + "name": "_value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "_value", + "type": "uint256" + } + ], + "name": "Burned", + "type": "event" + } + ], + "unlinked_binary": "0x6060604052341561000f57600080fd5b604051602080610682833981016040528080519150505b60008190555b505b6106458061003d6000396000f300606060405236156100965763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461009b57806318160ddd146100d157806323b872dd146100f6578063410085df1461013257806342966c681461016857806370a0823114610180578063a0712d68146101b1578063a9059cbb146101c9578063dd62ed3e146101ff575b600080fd5b34156100a657600080fd5b6100bd600160a060020a0360043516602435610236565b604051901515815260200160405180910390f35b34156100dc57600080fd5b6100e46102a6565b60405190815260200160405180910390f35b341561010157600080fd5b6100bd600160a060020a03600435811690602435166044356102ac565b604051901515815260200160405180910390f35b341561013d57600080fd5b6100bd600160a060020a0360043516602435610433565b604051901515815260200160405180910390f35b341561017357600080fd5b61017e600435610498565b005b341561018b57600080fd5b6100e4600160a060020a03600435166104f7565b60405190815260200160405180910390f35b34156101bc57600080fd5b61017e600435610516565b005b34156101d457600080fd5b6100bd600160a060020a0360043516602435610522565b604051901515815260200160405180910390f35b341561020a57600080fd5b6100e4600160a060020a03600435811690602435166105ec565b60405190815260200160405180910390f35b600160a060020a03338116600081815260026020908152604080832094871680845294909152808220805486019055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a35060015b92915050565b60005481565b600160a060020a0383166000908152600160205260408120548290108015906102d55750600082115b80156102fa5750600160a060020a038316600090815260016020526040902054828101115b156104275783600160a060020a031633600160a060020a0316141561038657600160a060020a038085166000818152600160205260408082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a350600161042b565b8161039185336105ec565b1161042157600160a060020a038085166000818152600260209081526040808320338616845282528083208054889003905583835260019091528082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a350600161042b565b5b61042b565b5060005b5b9392505050565b600160a060020a03821660009081526001602052604081205482901080159061045c5750600082115b156104895750600160a060020a0382166000908152600160208190526040909120805483900390556102a0565b5060006102a0565b5b92915050565b600160a060020a0333166000908152600160205260408082208054849003905581548390039091557fd83c63197e8e676d80ab0122beba9a9d20f3828839e9a1d6fe81d242e9cd7e6e9082905190815260200160405180910390a15b50565b600160a060020a0381166000908152600160205260409020545b919050565b60008054820190555b50565b600160a060020a03331660009081526001602052604081205482901080159061054b5750600082115b80156105705750600160a060020a038316600090815260016020526040902054828101115b156105e257600160a060020a033381166000818152600160205260408082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060016102a0565b5060005b92915050565b600160a060020a038083166000908152600260209081526040808320938516835292905220545b929150505600a165627a7a723058205ec42460f00182feefcbd720bda85d33d18fc051862c2cc38570e4c4596b58d50029", + "networks": { + "1509327668930": { + "events": { + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef": { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "_from", + "type": "address" + }, + { + "indexed": true, + "name": "_to", + "type": "address" + }, + { + "indexed": false, + "name": "_value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925": { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "_owner", + "type": "address" + }, + { + "indexed": true, + "name": "_spender", + "type": "address" + }, + { + "indexed": false, + "name": "_value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + "0xb90306ad06b2a6ff86ddc9327db583062895ef6540e62dc50add009db5b356eb": { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "_value", + "type": "uint256" + } + ], + "name": "Burn", + "type": "event" + } + }, + "links": {}, + "address": "0xdfab00cb6ed935bc6621ae4eeced6502c0b175d7", + "updated_at": 1509327705379 + }, + "1509337117897": { + "events": { + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef": { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "_from", + "type": "address" + }, + { + "indexed": true, + "name": "_to", + "type": "address" + }, + { + "indexed": false, + "name": "_value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925": { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "_owner", + "type": "address" + }, + { + "indexed": true, + "name": "_spender", + "type": "address" + }, + { + "indexed": false, + "name": "_value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + "0xd83c63197e8e676d80ab0122beba9a9d20f3828839e9a1d6fe81d242e9cd7e6e": { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "_value", + "type": "uint256" + } + ], + "name": "Burned", + "type": "event" + } + }, + "links": {}, + "address": "0x01b8acb538ba120d6e6da1bb17dbfe8608c183e6", + "updated_at": 1509337129593 + } + }, + "schema_version": "0.0.5", + "updated_at": 1509337129593 +} \ No newline at end of file diff --git a/contracts/Crowdsale.sol b/contracts/Crowdsale.sol index 576ec7e2..b6243eb3 100644 --- a/contracts/Crowdsale.sol +++ b/contracts/Crowdsale.sol @@ -2,13 +2,148 @@ pragma solidity ^0.4.15; import './Queue.sol'; import './Token.sol'; +import './utils/SafeMath.sol'; /** * @title Crowdsale - * @dev Contract that deploys `Token.sol` - * Is timelocked, manages buyer queue, updates balances on `Token.sol` + * @dev Contract that deploys Token.sol + * Is timelocked, manages buyer queue, updates balances on Token.sol */ contract Crowdsale { - // YOUR CODE HERE + address public creator; + uint public totalRaised; // measured in token + uint public currentBalence; // measured in wei + uint public startingTime; + uint public endingTime; + uint public exchangeRate; + Token private token; + Queue public queue; + + event TokenDelivered(address receiver, bool status); + event EtherRefunded(address receiver, bool status); + + modifier isCreator() { + require(msg.sender == creator); + _; + } + + modifier saleHasEnded() { + require(now > endingTime); + _; + } + + modifier saleHasNotEnded() { + require(startingTime <= now && now <= endingTime); + _; + } + + + function Crowdsale( + uint256 _exhangeRate, + uint256 _totalSupply, + uint _timeInMinutesForFundraising, + uint _qtimelimit) + { + startingTime = now; + endingTime = SafeMath.add(startingTime, SafeMath.mul(_timeInMinutesForFundraising, 1 minutes)); + //endingTime = startingTime + (_timeInMinutesForFundraising * 1 minutes); + creator = msg.sender; + exchangeRate = _exhangeRate; + token = new Token(_totalSupply); + queue = new Queue(_qtimelimit); + totalRaised = 0; + currentBalence = 0; + } + + function mint(uint256 amount) isCreator() { + token.mint(amount); + } + + function burn(uint256 amount) isCreator() { + token.burn(amount); + } + + function weiToToken(uint256 weiAmount) returns (uint256) { + return SafeMath.mul(weiAmount, exchangeRate); + } + + function tokenToWei(uint256 tokenAmount) returns (uint256) { + return SafeMath.div(tokenAmount, exchangeRate); + } + + function deliver() payable saleHasNotEnded() returns (bool) { + uint tokensAmount = weiToToken(msg.value); + uint difference = SafeMath.sub(token.totalSupply(), totalRaised); + if (tokensAmount > difference) { + //revert(); + msg.sender.transfer(msg.value); + return false; + } + + queue.enqueue(msg.sender); + + + while (queue.checkPlace() > 1 || queue.checkPlace() == 0) { // wait until being the first buyer + continue; + } + + + require(queue.checkPlace() == 1); + return true; + + while (queue.qsize() < 1) { // make sure the buyer always have ppl behind + queue.checkTime(); + if (queue.checkPlace(msg.sender) == 0) { // times up + //revert(); + msg.sender.transfer(msg.value); + TokenDelivered(msg.sender, false); + return false; + } + continue; + } + queue.checkTime(); + + + if (queue.checkPlace() == 0) { // times up + //revert(); + msg.sender.transfer(msg.value); + TokenDelivered(msg.sender, false); + return false; + } + + + queue.dequeue(); + bool success = token.transfer(msg.sender, tokensAmount); + if (success) { + totalRaised = SafeMath.add(totalRaised, weiToToken(msg.value)); + currentBalence = SafeMath.add(currentBalence, msg.value); + //currentBalence += msg.value; + } + TokenDelivered(msg.sender, success); + return success; + + } + + + function refund(uint256 amount) returns (bool) { + bool good = token.refund(msg.sender, amount); + if (good) { + uint256 refundAmount = tokenToWei(amount); + good = msg.sender.send(refundAmount); + } + EtherRefunded(msg.sender, good); // event + return good; + } + + function withdrawFunds() saleHasEnded() isCreator() returns (bool) { + return creator.send(currentBalence); + } + + function removeContract() public isCreator() saleHasEnded() { + selfdestruct(msg.sender); + } + + function () { revert(); } + } diff --git a/contracts/Queue.sol b/contracts/Queue.sol index fe0a4275..512358d3 100644 --- a/contracts/Queue.sol +++ b/contracts/Queue.sol @@ -8,52 +8,83 @@ pragma solidity ^0.4.15; */ contract Queue { - /* State variables */ + uint8 size = 5; - // YOUR CODE HERE + uint timeLimit; + uint8 currentSize; + Participant[] ParticipantsList; - /* Add events */ - // YOUR CODE HERE + struct Participant { + address a; + uint timeStamp; + } - /* Add constructor */ - // YOUR CODE HERE + function Queue(uint _timeLimit) { + // initinital constructor + currentSize = 0; + timeLimit = _timeLimit; + } /* Returns the number of people waiting in line */ function qsize() constant returns(uint8) { - // YOUR CODE HERE + return currentSize; } /* Returns whether the queue is empty or not */ function empty() constant returns(bool) { - // YOUR CODE HERE + return (currentSize == 0); } - + /* Returns the address of the person in the front of the queue */ function getFirst() constant returns(address) { - // YOUR CODE HERE + if (currentSize > 0) { + return ParticipantsList[0].a; + } + return address(0); } - - /* Allows `msg.sender` to check their position in the queue */ - function checkPlace() constant returns(uint8) { - // YOUR CODE HERE + + /* Allows `msg.sender` to check their position in the queue. + * Returns the 1-indexed position of the sender in the line. + * If person is not in line, returns 0. + */ + function checkPlace(address add) constant returns(uint8) { + for (uint8 i = 0; i < currentSize; i++) { + if(ParticipantsList[i].a == add) { + return i; + } + } + return 0; } - + /* Allows anyone to expel the first person in line if their time * limit is up */ function checkTime() { - // YOUR CODE HERE + if ( + currentSize > 0 && + ParticipantsList[0].timeStamp + timeLimit < now) + { + dequeue(); + } } - + /* Removes the first person in line; either when their time is up or when * they are done with their purchase */ function dequeue() { - // YOUR CODE HERE + if (currentSize > 0) { + delete ParticipantsList[0]; + currentSize -= 1; + } } /* Places `addr` in the first empty position in the queue */ function enqueue(address addr) { - // YOUR CODE HERE + if(currentSize >= size){ + //revert(); + return; + } + ParticipantsList.push(Participant( addr, now )); + currentSize += 1; } } diff --git a/contracts/Token.sol b/contracts/Token.sol index 7c23c4cf..0005fe9a 100644 --- a/contracts/Token.sol +++ b/contracts/Token.sol @@ -10,4 +10,113 @@ import './interfaces/ERC20Interface.sol'; contract Token is ERC20Interface { // YOUR CODE HERE + + // we need functions from token including following: + // - token.mint(amount); + // - token.burn(amount); + // - token.totalSupply() + // - token.transfer(msg.sender, tokensAmount); + // - token.refund(msg.sender, amount); + // ---> these 5 functions + event Transfer(address indexed _from, address indexed _to, uint256 _value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + event Burned(uint256 _value, uint256 _total); + + // Balances for each account + mapping(address => uint256) private balances; + + // Owner of account approves the transfer of an amount to another account + mapping(address => mapping (address => uint256)) allowed; + + function Token(uint _totalSupplyAmount) public{ + totalSupply = _totalSupplyAmount; + } + + function totalToken() public returns (uint256){ + return totalSupply; + } + + function mint(uint256 _amount) public{ + balances[msg.sender] = balances[msg.sender] + _amount; + totalSupply = totalSupply + _amount; + } + + function burn(uint256 _amount) public{ + balances[msg.sender] = balances[msg.sender] - _amount; + totalSupply = totalSupply - _amount; + Burned(_amount, totalSupply); + } + + /// @notice send `_value` token to `_to` from `msg.sender` + /// @param _to The address of the recipient + /// @param _value The amount of token to be transferred + /// @return Whether the transfer was successful or not + function transfer(address _to, uint256 _value) public returns (bool) { + if (balances[msg.sender] >= _value && _value > 0 && balances[_to] + _value > balances[_to]) { + balances[msg.sender] -= _value; + balances[_to] += _value; + Transfer(msg.sender, _to, _value); + return true; + } else { + return false; + } + } + + /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` + /// @param _from The address of the sender + /// @param _to The address of the recipient + /// @param _value The amount of token to be transferred + /// @return Whether the transfer was successful or not + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ + if (balances[_from] >= _value && _value > 0 && balances[_to] + _value > balances[_to]) { + if(msg.sender==_from){ + balances[_from] -= _value; + balances[_to] += _value; + Transfer(_from, _to, _value); + return true; + } else if (allowance(_from, msg.sender)<=_value){ + allowed[_from][msg.sender] -= _value; + balances[_from] -= _value; + balances[_to] += _value; + Transfer(_from, _to, _value); + return true; + } + } else { + return false; + } + } + + function refund(address _from, uint256 _value) public returns (bool success){ + if (balances[_from] >= _value && _value > 0) { + balances[_from] = balances[_from] - _value; + return true; + } else { + return false; + } + } + + /// @param _owner The address from which the balance will be retrieved + /// @return The balance + function balanceOf(address _owner) public constant returns (uint256 balance){ + return balances[_owner]; + } + + /// @notice `msg.sender` approves `_spender` to spend `_value` tokens + /// @param _spender The address of the account able to transfer the tokens + /// @param _value The amount of tokens to be approved for transfer + /// @return Whether the approval was successful or not + function approve(address _spender, uint256 _value) public returns (bool success){ + allowed[msg.sender][_spender] += _value; + Approval(msg.sender, _spender, _value); + return true; + } + + /// @param _owner The address of the account owning tokens + /// @param _spender The address of the account able to transfer the tokens + /// @return Amount of remaining tokens allowed to spent + function allowance(address _owner, address _spender) public constant returns (uint256 remaining){ + return allowed[_owner][_spender]; + } + + } diff --git a/contracts/interfaces/ERC20Interface.sol b/contracts/interfaces/ERC20Interface.sol index b1c74cde..d8e5a91a 100644 --- a/contracts/interfaces/ERC20Interface.sol +++ b/contracts/interfaces/ERC20Interface.sol @@ -7,7 +7,7 @@ pragma solidity ^0.4.15; */ contract ERC20Interface { /* This is a slight change to the ERC20 base standard. - + function totalSupply() constant returns (uint256 supply); is replaced with: uint256 public totalSupply; diff --git a/test/TestCrowdSale.js b/test/TestCrowdSale.js new file mode 100644 index 00000000..b2646c19 --- /dev/null +++ b/test/TestCrowdSale.js @@ -0,0 +1,100 @@ +'use strict'; + +/* Add the dependencies you're testing */ +const Crowdsale = artifacts.require("./Crowdsale.sol"); +// YOUR CODE HERE + +contract('TestCrowdsale', function(accounts) { + /* Define your constant variables and instantiate constantly changing + * ones + */ + const exchangeRate = 10; + const totalSupply = 1000; + const timeLimit = 100; + const qtime = 1; + const owner = accounts[0]; + const buyer1 = accounts[1]; + const buyer2 = accounts[2]; + + + let crowdsale; + // YOUR CODE HERE + + /* Do something before every `describe` method */ + beforeEach(async function() { + // YOUR CODE HERE + let c = await Crowdsale.new( + exchangeRate, + totalSupply, + timeLimit, + qtime, + {from: owner}, + ); + crowdsale = c; + }); + + /* Group test cases together + * Make sure to provide descriptive strings for method arguements and + * assert statements + */ + describe('Initialization', function() { + it("TestInit", async function() { + // YOUR CODE HERE + let creator = await crowdsale.creator.call(); + let totalRaised = await crowdsale.totalRaised.call(); + let currentBalance = await crowdsale.currentBalence.call(); + let startingTime = await crowdsale.startingTime.call(); + let endingTime = await crowdsale.endingTime.call(); + assert.equal(owner, creator.valueOf(), "no creator"); + assert.equal(0, totalRaised.valueOf(), "initial raise should be 0"); + assert.equal(0, currentBalance.valueOf(), "should have 0 balance to begin with") + assert.isAtMost(startingTime.valueOf(), endingTime.valueOf(), "ending time should be more than startingTime") + }); + // YOUR CODE HERE + }); + + describe('Sale', function() { + it("TestExchange", async function() { + // YOUR CODE HERE + let wei = 100; + let token = await crowdsale.weiToToken.call(wei); + assert.equal(wei*exchangeRate, token.valueOf(), "incorrect excahngerate") + }); + it("TestExchangeBack", async function() { + // YOUR CODE HERE + let token = 100; + let wei = await crowdsale.tokenToWei.call(token); + assert.equal(token/exchangeRate, wei.valueOf(), "incorrect excahngerate") + }); + /** + it("TestDelivering", async function() { + // YOUR CODE HERE + let boolean = await crowdsale.deliver.call({from: buyer1, value: 10}); + let boolean2 = await crowdsale.deliver.call({from: buyer2, value: 10}); + assert.equal(true, boolean, "failed transaction") + let tokensold = await crowdsale.totalRaised.call(); + let curBalance = await crowdsale.currentBalance.call(); + assert.equal(tokensold, 10, "different token sold amount"); + assert.equal(curBalance, 10*exchangeRate, "different currentBalance"); + + }); + */ + /** + it("TestRefund", async function() { + let boolean = await crowdsale.refund.call(10*exchangeRate, {from: buyer1}); + assert.equal(true, boolean, "failed transaction"); + let tokensold = await crowdsale.totalRaised.call(); + let curBalance = await crowdsale.currentBalance.call(); + assert.equal(tokensold, 0, "different token sold amount"); + assert.equal(curBalance, 0, "different currentBalance"); + }); + */ + + + // YOUR CODE HERE + }); + + describe('Your string here', function() { + // YOUR CODE HERE + }); +}); \ No newline at end of file diff --git a/test/TestCrowdSaleEnded.js b/test/TestCrowdSaleEnded.js new file mode 100644 index 00000000..0503d761 --- /dev/null +++ b/test/TestCrowdSaleEnded.js @@ -0,0 +1,83 @@ +'use strict'; + +/* Add the dependencies you're testing */ +const Crowdsale = artifacts.require("./Crowdsale.sol"); +// YOUR CODE HERE + +contract('TestCrowdsale', function(accounts) { + /* Define your constant variables and instantiate constantly changing + * ones + */ + const exchangeRate = 10; + const totalSupply = 1000; + const timeLimit = 0; + const qtime = 1; + const owner = accounts[0]; + const buyer1 = accounts[1]; + const buyer2 = accounts[2]; + + + let crowdsale; + // YOUR CODE HERE + + /* Do something before every `describe` method */ + beforeEach(async function() { + // YOUR CODE HERE + let c = await Crowdsale.new( + exchangeRate, + totalSupply, + timeLimit, + qtime, + {from: owner}, + ); + crowdsale = c; + }); + + /* Group test cases together + * Make sure to provide descriptive strings for method arguements and + * assert statements + */ + describe('Initialization', function() { + it("TestInit", async function() { + // YOUR CODE HERE + let creator = await crowdsale.creator.call(); + let totalRaised = await crowdsale.totalRaised.call(); + let currentBalance = await crowdsale.currentBalence.call(); + let startingTime = await crowdsale.startingTime.call(); + let endingTime = await crowdsale.endingTime.call(); + assert.equal(owner, creator.valueOf(), "no creator"); + assert.equal(0, totalRaised.valueOf(), "initial raise should be 0"); + assert.equal(0, currentBalance.valueOf(), "should have 0 balance to begin with") + assert.isAtMost(startingTime.valueOf(), endingTime.valueOf(), "ending time should be more than startingTime") + }); + // YOUR CODE HERE + }); + /** + describe('Sale', function() { + it("TestSaleAfterEnd", async function() { + // YOUR CODE HERE + let startTime = await crowdsale.startingTime.call(); + let endTime = await crowdsale.endingTime.call(); + while (endTime <= startTime) { + endTime = await crowdsale.endingTime.call(); + continue; + } + + let boolean = await crowdsale.deliver.call({from: buyer1, value: 10}); + assert.equal(false, boolean, "buyer shouldnt be able to buy"); + let tokensold = await crowdsale.totalRaised.call(); + let curBalance = await crowdsale.currentBalance.call(); + assert.equal(tokensold, 0, "different token sold amount"); + assert.equal(curBalance, 0, "different currentBalance"); + + }); + + // YOUR CODE HERE + }); + */ + + + describe('Your string here', function() { + // YOUR CODE HERE + }); +}); \ No newline at end of file diff --git a/test/TestQueue.js b/test/TestQueue.js new file mode 100644 index 00000000..df7f198b --- /dev/null +++ b/test/TestQueue.js @@ -0,0 +1,57 @@ + +const Queue = artifacts.require("./Queue.sol"); + +contract('TestQueue', function(accounts){ + let queue; + beforeEach(async function() { + let q = await Queue.new(5); + queue = q; + }); + + describe('Test queue operations', function(){ + it("Testing enqueue operations, qsize should increment upon enqueue", async function() { + await queue.enqueue(0); + let size = await queue.qsize.call(); + assert.equal( size, 1, "qsize should equal 1"); + }), + it("Testing enqueue operations, adding more than 5 participants should fail.", async function() { + for(let i = 0; i < 10; i++){ + await queue.enqueue(i); + } + let size = await queue.qsize.call(); + assert.equal(size, 5, "qsize should never be more than 5"); + }), + it("Testing dequeue after enqueue", async function() { + await queue.enqueue(1); + await queue.enqueue(2); + await queue.enqueue(3); + await queue.dequeue(); + let size = await queue.qsize.call(); + assert.equal(size, 2, "Adding 3 participants and dequeueing, should result in 2 participants."); + }), + it("getFirst should fetch address correspponding to the first participant in queue", async function() { + await queue.enqueue(accounts[0]); + await queue.enqueue(accounts[1]); + let first = await queue.getFirst.call(); + assert.equal(first, accounts[0], "First person in queue"); + }), + it("checkPlace should return position of participant", async function() { + await queue.enqueue(accounts[0]); + await queue.enqueue(accounts[1]); + await queue.enqueue(accounts[2]); + let position = await queue.checkPlace.call(accounts[1]); + assert.equal(position, 1, "accounts[1] is at position 1"); + }) + }); + describe("Test participant time limits", function(){ + it("checkTime for first participant in queue should work", async function(){ + await queue.enqueue(accounts[0]); + + setTimeout( async function(){ + await queue.checkTime(); + let size = await queue.qsize.call(); + assert.equal(size, 0, "checktime after waiting 3 seconds should remove participant from queue"); + }, 3000); + }) + }) +}); diff --git a/test/TestToken.js b/test/TestToken.js new file mode 100644 index 00000000..72440b52 --- /dev/null +++ b/test/TestToken.js @@ -0,0 +1,54 @@ + +const Crowdsale = artifacts.require("./Crowdsale.sol"); +const Token = artifacts.require("./Token.sol"); + +contract('TestToken', function(accounts){ + let token; + beforeEach(async function() { + let t = await Token.new(0); + token = t; + }); + + describe('Test token operations', function(){ + it("Testing minting and burning", async function() { + let total = await token.totalSupply.call(); + assert.equal(total , 0, "totalSupply is initialized at 0"); + await token.mint(5); + total = await token.totalSupply.call(); + //console.log(token.totalSupply); + assert.equal(total , 5, "totalSupply should equal 5"); + await token.burn(2); + total = await token.totalSupply.call(); + assert.equal(total , 3, "totalSupply should equal 3"); + }), + it("Testing transfer", async function() { + await token.mint(10); + await token.transfer(accounts[1], 3); + //console.log(await token.balanceOf(accounts[1])); + await token.transfer(accounts[2], 4); + //console.log(await token.balanceOf(accounts[2])); + let total1 = await token.balanceOf(accounts[1]); + assert.equal(total1 , 3, "address 0 should have 3 in its account"); + let total2 = await token.balanceOf(accounts[2]); + assert.equal(total2 , 4, "address 1 should have 4 in its account"); + }) + it("Testing transferFrom", async function() { + await token.mint(10); + await token.approve(accounts[1], 4); + let allowed = await token.allowance(accounts[0], accounts[1]); + assert.equal(allowed , 4, "address 1 should be allowed to transfer 4 from address 0's account"); + await token.transferFrom(accounts[0], accounts[2], 4); + let transfered = await token.balanceOf(accounts[2]); + assert.equal(transfered , 4, "address 2 should have 4 in its account"); + }) + it("Testing refund", async function() { + await token.mint(10); + await token.refund(accounts[0], 3); + let afterRefund = await token.balanceOf(accounts[0]); + assert.equal(afterRefund , 7, "should have removed 3 from the account"); + await token.refund(accounts[0], 9); + afterRefund = await token.balanceOf(accounts[0]); + assert.equal(afterRefund , 7, false, "can't refund more than is in the account"); + }) + }); +});