embark-area-51/test/compiler.js

37 lines
12 KiB
JavaScript

/*globals describe, it*/
let Compiler = require('../lib/contracts/compiler.js');
let TestLogger = require('../lib/core/test_logger.js');
let File = require('../lib/core/file.js');
let assert = require('assert');
let fs = require('fs');
let readFile = function(file) {
return new File({filename: file, type: 'dapp_file', path: file});
};
describe('embark.Compiler', function() {
let compiler = new Compiler({logger: new TestLogger({}), solcVersion: '0.4.11'});
describe('#compile_solidity', function() {
this.timeout(0);
let expectedObject = {};
expectedObject["SimpleStorage"] = {"code":"6060604052341561000c57fe5b60405160208061011383398101604052515b60008190555b505b60df806100346000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c0029","filename": "test/contracts/simple_storage.sol","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"}]};
expectedObject["Token"] = {"code":"6060604052341561000c57fe5b6040516020806104be83398101604052515b600160a060020a033316600090815260208190526040902081905560028190555b505b61046e806100506000396000f300606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007757806318160ddd146100aa57806323b872dd146100cc57806370a0823114610105578063a9059cbb14610133578063dd62ed3e14610166575bfe5b341561007f57fe5b610096600160a060020a036004351660243561019a565b604080519115158252519081900360200190f35b34156100b257fe5b6100ba610205565b60408051918252519081900360200190f35b34156100d457fe5b610096600160a060020a036004358116906024351660443561020c565b604080519115158252519081900360200190f35b341561010d57fe5b6100ba600160a060020a0360043516610323565b60408051918252519081900360200190f35b341561013b57fe5b610096600160a060020a0360043516602435610342565b604080519115158252519081900360200190f35b341561016e57fe5b6100ba600160a060020a0360043581169060243516610407565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a038316600090815260208190526040812054829010156102335760006000fd5b600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010156102685760006000fd5b600160a060020a03831660009081526020819052604090205461028b9083610434565b15156102975760006000fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a033316600090815260208190526040812054829010156103695760006000fd5b600160a060020a03831660009081526020819052604090205461038c9083610434565b15156103985760006000fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b808201829010155b929150505600a165627a7a72305820f1e53450d0d5723ba8f341856e7786c43607109cbb25ff3975ce9ccd042506b30029","filename": "test/contracts/token.sol","realRuntimeBytecode": "606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007757806318160ddd146100aa57806323b872dd146100cc57806370a0823114610105578063a9059cbb14610133578063dd62ed3e14610166575bfe5b341561007f57fe5b610096600160a060020a036004351660243561019a565b604080519115158252519081900360200190f35b34156100b257fe5b6100ba610205565b60408051918252519081900360200190f35b34156100d457fe5b610096600160a060020a036004358116906024351660443561020c565b604080519115158252519081900360200190f35b341561010d57fe5b6100ba600160a060020a0360043516610323565b60408051918252519081900360200190f35b341561013b57fe5b610096600160a060020a0360043516602435610342565b604080519115158252519081900360200190f35b341561016e57fe5b6100ba600160a060020a0360043581169060243516610407565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a038316600090815260208190526040812054829010156102335760006000fd5b600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010156102685760006000fd5b600160a060020a03831660009081526020819052604090205461028b9083610434565b15156102975760006000fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a033316600090815260208190526040812054829010156103695760006000fd5b600160a060020a03831660009081526020819052604090205461038c9083610434565b15156103985760006000fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b808201829010155b929150505600a165627a7a72305820","runtimeBytecode":"606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007757806318160ddd146100aa57806323b872dd146100cc57806370a0823114610105578063a9059cbb14610133578063dd62ed3e14610166575bfe5b341561007f57fe5b610096600160a060020a036004351660243561019a565b604080519115158252519081900360200190f35b34156100b257fe5b6100ba610205565b60408051918252519081900360200190f35b34156100d457fe5b610096600160a060020a036004358116906024351660443561020c565b604080519115158252519081900360200190f35b341561010d57fe5b6100ba600160a060020a0360043516610323565b60408051918252519081900360200190f35b341561013b57fe5b610096600160a060020a0360043516602435610342565b604080519115158252519081900360200190f35b341561016e57fe5b6100ba600160a060020a0360043581169060243516610407565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a038316600090815260208190526040812054829010156102335760006000fd5b600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010156102685760006000fd5b600160a060020a03831660009081526020819052604090205461028b9083610434565b15156102975760006000fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a033316600090815260208190526040812054829010156103695760006000fd5b600160a060020a03831660009081526020819052604090205461038c9083610434565b15156103985760006000fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b808201829010155b929150505600a165627a7a72305820f1e53450d0d5723ba8f341856e7786c43607109cbb25ff3975ce9ccd042506b30029","swarmHash": "f1e53450d0d5723ba8f341856e7786c43607109cbb25ff3975ce9ccd042506b3","gasEstimates":{"creation":[40472,226800],"external":{"allowance(address,address)":809,"approve(address,uint256)":22334,"balanceOf(address)":673,"totalSupply()":396,"transfer(address,uint256)":43635,"transferFrom(address,address,uint256)":64415},"internal":{"safeToAdd(uint256,uint256)":41}},"functionHashes":{"allowance(address,address)":"dd62ed3e","approve(address,uint256)":"095ea7b3","balanceOf(address)":"70a08231","totalSupply()":"18160ddd","transfer(address,uint256)":"a9059cbb","transferFrom(address,address,uint256)":"23b872dd"},"abiDefinition":[{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"ok","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"supply","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":"ok","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"who","type":"address"}],"name":"balanceOf","outputs":[{"name":"value","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"ok","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"_allowance","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initial_balance","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"}]}
it('should generate compiled code and abi', function(done) {
compiler.compile_solidity([
readFile('test/contracts/simple_storage.sol'),
readFile('test/contracts/token.sol')
], function(err, compiledContracts) {
assert.deepEqual(compiledContracts, expectedObject);
done();
});
});
});
});