embark/test/compiler.js

51 lines
12 KiB
JavaScript
Raw Normal View History

/*globals describe, it*/
2017-12-16 21:05:46 +00:00
let SolidityCompiler = require('../lib/modules/solidity');
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');
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});
};
2017-12-30 22:07:13 +00:00
var solcVersion = "0.4.17";
var TestEvents = {
request: (cmd, cb) => {
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
};
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/']});
describe('#compile_solidity', function() {
this.timeout(0);
2017-03-29 17:57:22 +00:00
let expectedObject = {};
2018-01-27 20:07:55 +00:00
expectedObject["SimpleStorage"] = {"code":"6060604052341561000f57600080fd5b60405160208061010883398101604052808051600055505060d3806100356000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604f57806360fe47b11460715780636d4ce63c14608657600080fd5b3415605957600080fd5b605f6096565b60405190815260200160405180910390f35b3415607b57600080fd5b6084600435609c565b005b3415609057600080fd5b605f60a1565b60005481565b600055565b600054905600a165627a7a72305820330a7d10dd5f07c8182fbdff4e0f5c5994830dbc4f07922898d06486526bead30029","runtimeBytecode":"606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604f57806360fe47b11460715780636d4ce63c14608657600080fd5b3415605957600080fd5b605f6096565b60405190815260200160405180910390f35b3415607b57600080fd5b6084600435609c565b005b3415609057600080fd5b605f60a1565b60005481565b600055565b600054905600a165627a7a72305820330a7d10dd5f07c8182fbdff4e0f5c5994830dbc4f07922898d06486526bead30029","realRuntimeBytecode":"606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604f57806360fe47b11460715780636d4ce63c14608657600080fd5b3415605957600080fd5b605f6096565b60405190815260200160405180910390f35b3415607b57600080fd5b6084600435609c565b005b3415609057600080fd5b605f60a1565b60005481565b600055565b600054905600a165627a7a72305820","swarmHash":"330a7d10dd5f07c8182fbdff4e0f5c5994830dbc4f07922898d06486526bead3","gasEstimates":{"creation":{"codeDepositCost":"42200","executionCost":"20140","totalCost":"62340"},"external":{"get()":"396","set(uint256)":"20135","storedData()":"352"}},"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-01-27 20:07:55 +00:00
expectedObject["Token"] = {"code":"6060604052341561000f57600080fd5b60405160208061047583398101604052808051600160a060020a03331660009081526020819052604090208190556002555050610424806100516000396000f300606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007a57806318160ddd146100b057806323b872dd146100d557806370a08231146100fd578063a9059cbb1461011c578063dd62ed3e1461013e575b600080fd5b341561008557600080fd5b61009c600160a060020a0360043516602435610163565b604051901515815260200160405180910390f35b34156100bb57600080fd5b6100c36101cf565b60405190815260200160405180910390f35b34156100e057600080fd5b61009c600160a060020a03600435811690602435166044356101d5565b341561010857600080fd5b6100c3600160a060020a03600435166102e9565b341561012757600080fd5b61009c600160a060020a0360043516602435610304565b341561014957600080fd5b6100c3600160a060020a03600435811690602435166103c6565b600160a060020a03338116600081815260016020908152604080832094871680845294909152808220859055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a350600192915050565b60025490565b600160a060020a038316600090815260208190526040812054829010156101fb57600080fd5b600160a060020a03808516600090815260016020908152604080832033909416835292905220548290101561022f57600080fd5b600160a060020a03831660009081526020819052604090205461025290836103f1565b151561025d57600080fd5b600160a060020a0380851660008181526001602090815260408083203386168452825280832080548890039055838352908290528082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060019392505050565b600160a060020a031660009081526020819052604090205490565b600160a060020a0333166000908152602081905260408120548290101561032a57600080fd5b600160a060020a03831660009081526020819052604090205461034d90836103f1565b151561035857600080fd5b600160a060020a033381166000818152602081905260408082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a350600192915050565b600160a060020a03918216600090815260016020908152604080832093909416825291909152205490565b81011015905600a165627a7a723058203c32962ee70b1d7d79b4ca95877ef502f88f4b06fd14a1464f74a1a84bb0f7c90029","runtimeBytecode":"606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007a57806318160ddd146100b057806323b872dd146100d557806370a08231146100fd578063a9059cbb1461011c578063dd62ed3e1461013e575b600080fd5b341561008557600080fd5b61009c600160a060020a0360043516602435610163565b604051901515815260200160405180910390f35b34156100bb57600080fd5b6100c36101cf565b60405190815260200160405180910390f35b34156100e057600080fd5b61009c600160a060020a03600435811690602435166044356101d5565b341561010857600080fd5b6100c3600160a060020a03600435166102e9565b341561012757600080fd5b61009c600160a060020a0360043516602435610304565b341561014957600080fd5b6100c3600160a060020a03600435811690602435166103c6565b600160a060020a03338116600081815260016020908152604080832094871680845294909152808220859055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a350600192915050565b60025490565b600160a060020a038316600090815260208190526040812054829010156101fb57600080fd5b600160a060020a03808516600090815260016020908152604080832033909416835292905220548290101561022f57600080fd5b600160a060020a03831660009081526020819052604090205461025290836103f1565b151561025d57600080fd5b600160a060020a0380851660008181526001602090815260408083203386168452825280832080548890039055838352908290528082208054879003905592861680825290839020805486019055917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060019392505050565b600160a060020a031660009081526020819052604090205490565b600160a060020a0333166000908152602081905260408120548290101561032a57600080fd5b600160a060020a03831660009081526020819052604090205461034d90836103f1565b151561035857600080fd5b600160a060020a0333811660008181526020819
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();
});
});
});
});