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');
|
|
|
|
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) {
|
2016-10-15 19:54:19 +00:00
|
|
|
return {filename: file, content: fs.readFileSync(file).toString()};
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('embark.Compiler', function() {
|
2017-03-29 17:57:22 +00:00
|
|
|
let compiler = new Compiler({logger: new TestLogger({})});
|
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:17:21 +00:00
|
|
|
expectedObject["SimpleStorage"] = {"code":"6060604052341561000c57fe5b60405160208061011383398101604052515b60008190555b505b60df806100346000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c0029","realRuntimeBytecode": "606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820","runtimeBytecode":"606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c0029","swarmHash": "a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c","gasEstimates":{"creation":[20141,44600],"external":{"get()":400,"set(uint256)":20144,"storedData()":335},"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-03-02 01:52:58 +00:00
|
|
|
expectedObject["Token"] = {"code":"6060604052346100005760405160208061048e83398101604052515b600160a060020a033316600090815260208190526040902081905560028190555b505b6104418061004d6000396000f3006060604052361561005c5763ffffffff60e060020a600035041663095ea7b3811461006157806318160ddd1461009157806323b872dd146100b057806370a08231146100e6578063a9059cbb14610111578063dd62ed3e14610141575b610000565b346100005761007d600160a060020a0360043516602435610172565b604080519115158252519081900360200190f35b346100005761009e6101dd565b60408051918252519081900360200190f35b346100005761007d600160a060020a03600435811690602435166044356101e4565b604080519115158252519081900360200190f35b346100005761009e600160a060020a03600435166102f8565b60408051918252519081900360200190f35b346100005761007d600160a060020a0360043516602435610317565b604080519115158252519081900360200190f35b346100005761009e600160a060020a03600435811690602435166103da565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a0383166000908152602081905260408120548290101561020a57610000565b600160a060020a03808516600090815260016020908152604080832033909416835292905220548290101561023e57610000565b600160a060020a0383166000908152602081905260409020546102619083610407565b151561026c57610000565b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a0333166000908152602081905260408120548290101561033d57610000565b600160a060020a0383166000908152602081905260409020546103609083610407565b151561036b57610000565b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b808201829010155b929150505600a165627a7a7230582017291fa7c1b9234972e866bb8b730096a40f8610da4684f7977498fc0ee8f75b0029","realRuntimeBytecode": "6060604052361561005c5763ffffffff60e060020a600035041663095ea7b3811461006157806318160ddd1461009157806323b872dd146100b057806370a08231146100e6578063a9059cbb14610111578063dd62ed3e14610141575b610000565b346100005761007d600160a060020a0360043516602435610172565b604080519115158252519081900360200190f35b346100005761009e6101dd565b60408051918252519081900360200190f35b346100005761007d600160a060020a03600435811690602435166044356101e4565b604080519115158252519081900360200190f35b346100005761009e600160a060020a03600435166102f8565b60408051918252519081900360200190f35b346100005761007d600160a060020a0360043516602435610317565b604080519115158252519081900360200190f35b346100005761009e600160a060020a03600435811690602435166103da565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a0383166000908152602081905260408120548290101561020a57610000565b600160a060020a03808516600090815260016020908152604080832033909416835292905220548290101561023e57610000565b600160a060020a0383166000908152602081905260409020546102619083610407565b151561026c57610000565b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a0333166000908152602081905260408120548290101561033d57610000565b600160a060020a038316600090815260208190
|
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
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|