2016-10-15 19:54:19 +00:00
|
|
|
/*globals describe, it*/
|
2017-03-29 17:57:22 +00:00
|
|
|
let Compiler = require('../lib/contracts/compiler.js');
|
|
|
|
let TestLogger = require('../lib/core/test_logger.js');
|
2017-07-08 16:39:53 +00:00
|
|
|
let File = require('../lib/core/file.js');
|
2017-03-29 17:57:22 +00:00
|
|
|
let assert = require('assert');
|
|
|
|
let fs = require('fs');
|
2016-10-15 19:54:19 +00:00
|
|
|
|
2017-03-29 17:57:22 +00:00
|
|
|
let readFile = function(file) {
|
2017-07-08 16:39:53 +00:00
|
|
|
return new File({filename: file, type: 'dapp_file', path: file});
|
2016-10-15 19:54:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
describe('embark.Compiler', function() {
|
2017-07-08 16:39:53 +00:00
|
|
|
let compiler = new Compiler({logger: new TestLogger({}), solcVersion: '0.4.11'});
|
2016-10-15 19:54:19 +00:00
|
|
|
|
|
|
|
describe('#compile_solidity', function() {
|
2017-03-08 14:38:08 +00:00
|
|
|
this.timeout(0);
|
2017-03-08 13:49:42 +00:00
|
|
|
|
2017-03-29 17:57:22 +00:00
|
|
|
let expectedObject = {};
|
2016-10-15 19:54:19 +00:00
|
|
|
|
2017-06-03 02:18:53 +00:00
|
|
|
expectedObject["SimpleStorage"] = {"code":"6060604052341561000c57fe5b60405160208061011383398101604052515b60008190555b505b60df806100346000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c0029","realRuntimeBytecode": "606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820","runtimeBytecode":"606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c0029","swarmHash": "a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c","gasEstimates":{"creation":[20141,44600],"external":{"get()":400,"set(uint256)":20144,"storedData()":355},"internal":{}},"functionHashes":{"get()":"6d4ce63c","set(uint256)":"60fe47b1","storedData()":"2a1afcd9"},"abiDefinition":[{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"payable":false,"type":"constructor"}]};
|
2016-12-02 12:06:04 +00:00
|
|
|
|
2017-06-03 02:14:04 +00:00
|
|
|
expectedObject["Token"] = {"code":"6060604052341561000c57fe5b6040516020806104be83398101604052515b600160a060020a033316600090815260208190526040902081905560028190555b505b61046e806100506000396000f300606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007757806318160ddd146100aa57806323b872dd146100cc57806370a0823114610105578063a9059cbb14610133578063dd62ed3e14610166575bfe5b341561007f57fe5b610096600160a060020a036004351660243561019a565b604080519115158252519081900360200190f35b34156100b257fe5b6100ba610205565b60408051918252519081900360200190f35b34156100d457fe5b610096600160a060020a036004358116906024351660443561020c565b604080519115158252519081900360200190f35b341561010d57fe5b6100ba600160a060020a0360043516610323565b60408051918252519081900360200190f35b341561013b57fe5b610096600160a060020a0360043516602435610342565b604080519115158252519081900360200190f35b341561016e57fe5b6100ba600160a060020a0360043581169060243516610407565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a038316600090815260208190526040812054829010156102335760006000fd5b600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010156102685760006000fd5b600160a060020a03831660009081526020819052604090205461028b9083610434565b15156102975760006000fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a033316600090815260208190526040812054829010156103695760006000fd5b600160a060020a03831660009081526020819052604090205461038c9083610434565b15156103985760006000fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b808201829010155b929150505600a165627a7a72305820f1e53450d0d5723ba8f341856e7786c43607109cbb25ff3975ce9ccd042506b30029","realRuntimeBytecode": "606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007757806318160ddd146100aa57806323b872dd146100cc57806370a0823114610105578063a9059cbb14610133578063dd62ed3e14610166575bfe5b341561007f57fe5b610096600160a060020a036004351660243561019a565b604080519115158252519081900360200190f35b34156100b257fe5b6100ba610205565b60408051918252519081900360200190f35b34156100d457fe5b610096600160a060020a036004358116906024351660443561020c565b604080519115158252519081900360200190f35b341561010d57fe5b6100ba600160a060020a0360043516610323565b60408051918252519081900360200190f35b341561013b57fe5b610096600160a060020a0360043516602435610342565b604080519115158252519081900360200190f35b341561016e57fe5b6100ba600160a060020a0360043581169060243516610407565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a038316600090815260208190526040812054829010156102335760006000fd5b600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010156102685760006000fd5b600160a060020a03831660009081526020819052604090205461028b9083610434565b15156102975760006000fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b93925050
|
2016-10-15 19:54:19 +00:00
|
|
|
|
2017-02-17 12:14:44 +00:00
|
|
|
it('should generate compiled code and abi', function(done) {
|
|
|
|
compiler.compile_solidity([
|
|
|
|
readFile('test/contracts/simple_storage.sol'),
|
|
|
|
readFile('test/contracts/token.sol')
|
2017-02-28 13:07:07 +00:00
|
|
|
], function(err, compiledContracts) {
|
2017-02-26 04:20:57 +00:00
|
|
|
assert.deepEqual(compiledContracts, expectedObject);
|
2017-02-17 12:14:44 +00:00
|
|
|
done();
|
|
|
|
});
|
2016-10-15 19:54:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|