2016-10-15 19:54:19 +00:00
|
|
|
/*globals describe, it*/
|
2017-12-16 21:05:46 +00:00
|
|
|
let SolidityCompiler = require('../lib/modules/solidity');
|
2018-01-20 02:13:20 +00:00
|
|
|
let TestLogger = require('../lib/tests/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');
|
2016-10-15 19:54:19 +00:00
|
|
|
|
2017-03-29 17:57:22 +00:00
|
|
|
let readFile = function(file) {
|
2018-04-18 19:02:50 +00:00
|
|
|
return new File({filename: file, type: File.types.dapp_file, path: file});
|
2016-10-15 19:54:19 +00:00
|
|
|
};
|
|
|
|
|
2018-05-04 03:30:59 +00:00
|
|
|
var solcVersion = "0.4.23";
|
2017-12-30 22:07:13 +00:00
|
|
|
|
|
|
|
var TestEvents = {
|
|
|
|
request: (cmd, cb) => {
|
2018-04-10 20:38:49 +00:00
|
|
|
cb(solcVersion);
|
2017-12-30 22:07:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-16 21:05:46 +00:00
|
|
|
var apiObject = {
|
|
|
|
registerCompiler: function() {},
|
2017-12-30 22:07:13 +00:00
|
|
|
logger: new TestLogger({}),
|
|
|
|
events: TestEvents
|
2017-12-16 21:05:46 +00:00
|
|
|
};
|
|
|
|
|
2016-10-15 19:54:19 +00:00
|
|
|
describe('embark.Compiler', function() {
|
2017-12-16 21:05:46 +00:00
|
|
|
//let compiler = new Compiler({logger: new TestLogger({})});
|
2017-12-30 22:07:13 +00:00
|
|
|
let compiler = new SolidityCompiler(apiObject, {contractDirectories: ['app/contracts/']});
|
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
|
|
|
|
2018-05-04 15:01:42 +00:00
|
|
|
expectedObject["SimpleStorage"] = {"code":"608060405234801561001057600080fd5b50604051602080610114833981016040525160005560e1806100336000396000f30060806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114605757806360fe47b114607b5780636d4ce63c146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820194e9895d54b0b5d8b469e794926ef9115b42631ab9a06ce726f9fea067633850029","runtimeBytecode":"60806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114605757806360fe47b114607b5780636d4ce63c146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820194e9895d54b0b5d8b469e794926ef9115b42631ab9a06ce726f9fea067633850029","realRuntimeBytecode":"60806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114605757806360fe47b114607b5780636d4ce63c146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820","swarmHash":"194e9895d54b0b5d8b469e794926ef9115b42631ab9a06ce726f9fea06763385","gasEstimates":{"creation":{"codeDepositCost":"45000","executionCost":"20141","totalCost":"65141"},"external":{"get()":"428","set(uint256)":"20161","storedData()":"384"}},"functionHashes":{"get()":"6d4ce63c","set(uint256)":"60fe47b1","storedData()":"2a1afcd9"},"abiDefinition":[{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}],"filename":"test/contracts/simple_storage.sol"};
|
2016-12-02 12:06:04 +00:00
|
|
|
|
2018-05-04 15:01:42 +00:00
|
|
|
expectedObject["Token"] = {"code":"608060405234801561001057600080fd5b5060405160208061047e8339810160409081529051600160a060020a033316600090815260208190529190912081905560025561042c806100526000396000f3006080604052600436106100775763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007c57806318160ddd146100b457806323b872dd146100db57806370a0823114610105578063a9059cbb14610126578063dd62ed3e1461014a575b600080fd5b34801561008857600080fd5b506100a0600160a060020a0360043516602435610171565b604080519115158252519081900360200190f35b3480156100c057600080fd5b506100c96101db565b60408051918252519081900360200190f35b3480156100e757600080fd5b506100a0600160a060020a03600435811690602435166044356101e1565b34801561011157600080fd5b506100c9600160a060020a03600435166102f2565b34801561013257600080fd5b506100a0600160a060020a036004351660243561030d565b34801561015657600080fd5b506100c9600160a060020a03600435811690602435166103ce565b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a350600192915050565b60025490565b600160a060020a03831660009081526020819052604081205482111561020657600080fd5b600160a060020a038085166000908152600160209081526040808320339094168352929052205482111561023957600080fd5b600160a060020a03831660009081526020819052604090205461025c90836103f9565b151561026757600080fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b600160a060020a031660009081526020819052604090205490565b600160a060020a03331660009081526020819052604081205482111561033257600080fd5b600160a060020a03831660009081526020819052604090205461035590836103f9565b151561036057600080fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a350600192915050565b600160a060020a03918216600090815260016020908152604080832093909416825291909152205490565b81011015905600a165627a7a72305820c34209c42f57b08f62d29e65db6744b4c8991eee33c4c83e0d81674550945da80029","runtimeBytecode":"6080604052600436106100775763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007c57806318160ddd146100b457806323b872dd146100db57806370a0823114610105578063a9059cbb14610126578063dd62ed3e1461014a575b600080fd5b34801561008857600080fd5b506100a0600160a060020a0360043516602435610171565b604080519115158252519081900360200190f35b3480156100c057600080fd5b506100c96101db565b60408051918252519081900360200190f35b3480156100e757600080fd5b506100a0600160a060020a03600435811690602435166044356101e1565b34801561011157600080fd5b506100c9600160a060020a03600435166102f2565b34801561013257600080fd5b506100a0600160a060020a036004351660243561030d565b34801561015657600080fd5b506100c9600160a060020a03600435811690602435166103ce565b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a350600192915050565b60025490565b600160a060020a03831660009081526020819052604081205482111561020657600080fd5b600160a060020a038085166000908152600160209081526040808320339094168352929052205482111561023957600080fd5b600160a060020a03831660009081526020819052604090205461025c90836103f9565b151561026757600080fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b600160a060020a031660009081526020819052604090205490565b600160a060020a03331660009081526020819052604081205482111561033257600080fd5b600160a060020a03831660009081526020819052604090205461035590836103f9565b151561036057600080fd5b60016
|
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
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|