embark-area-51/test/compiler.js

31 lines
7.5 KiB
JavaScript
Raw Normal View History

/*globals describe, it*/
var Compiler = require('../lib/compiler.js');
var assert = require('assert');
var fs = require('fs');
var readFile = function(file) {
return {filename: file, content: fs.readFileSync(file).toString()};
};
describe('embark.Compiler', function() {
var compiler = new Compiler();
describe('#compile_solidity', function() {
var compiledContracts = compiler.compile_solidity([
readFile('test/contracts/simple_storage.sol'),
readFile('test/contracts/token.sol')
]);
var expectedObject = {};
2016-10-22 22:20:52 +00:00
expectedObject["SimpleStorage"] = {"code":"6060604052604051602080608983395060806040525160008190555060628060276000396000f3606060405260e060020a60003504632a1afcd98114603057806360fe47b114603c5780636d4ce63c146048575b6002565b34600257605060005481565b34600257600435600055005b346002576000545b60408051918252519081900360200190f3","runtimeBytecode":"606060405260e060020a60003504632a1afcd98114603057806360fe47b114603c5780636d4ce63c146048575b6002565b34600257605060005481565b34600257600435600055005b346002576000545b60408051918252519081900360200190f3","gasEstimates":{"creation":[20100,19600],"external":{"get()":236,"set(uint256)":20124,"storedData()":206},"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"}],"type":"constructor"}]};
2016-10-22 22:20:52 +00:00
expectedObject["Token"] = {"code":"60606040526040516020806103a3833950608060405251600160a060020a033316600090815260208190526040902081905560028190555061035e806100456000396000f3606060405236156100565760e060020a6000350463095ea7b3811461005b57806318160ddd146100d557806323b872dd146100f057806370a0823114610127578063a9059cbb1461014c578063dd62ed3e14610180575b610002565b34610002576101b960043560243533600160a060020a03908116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b34610002576002545b60408051918252519081900360200190f35b34610002576101b9600435602435604435600160a060020a038316600090815260208190526040812054829010156101cd57610002565b3461000257600160a060020a03600435166000908152602081905260409020546100de565b34610002576101b960043560243533600160a060020a0316600090815260208190526040812054829010156102c257610002565b34610002576100de600435602435600160a060020a038281166000908152600160209081526040808320938516835292905220546100cf565b604080519115158252519081900360200190f35b600160a060020a03848116600090815260016020908152604080832033909416835292905220548290101561020157610002565b600160a060020a03831660009081526020819052604090205461022c90835b818101829010156100cf565b151561023757610002565b600160a060020a038481166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b600160a060020a0383166000908152602081905260409020546102e59083610220565b15156102f057610002565b33600160a060020a0390811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060016100cf56","runtimeBytecode":"606060405236156100565760e060020a6000350463095ea7b3811461005b57806318160ddd146100d557806323b872dd146100f057806370a0823114610127578063a9059cbb1461014c578063dd62ed3e14610180575b610002565b34610002576101b960043560243533600160a060020a03908116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b34610002576002545b60408051918252519081900360200190f35b34610002576101b9600435602435604435600160a060020a038316600090815260208190526040812054829010156101cd57610002565b3461000257600160a060020a03600435166000908152602081905260409020546100de565b34610002576101b960043560243533600160a060020a0316600090815260208190526040812054829010156102c257610002565b34610002576100de600435602435600160a060020a038281166000908152600160209081526040808320938516835292905220546100cf565b604080519115158252519081900360200190f35b600160a060020a03848116600090815260016020908152604080832033909416835292905220548290101561020157610002565b600160a060020a03831660009081526020819052604090205461022c90835b818101829010156100cf565b151561023757610002565b600160a060020a038481166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b600160a060020a0383166000908152602081905260409020546102e59083610220565b15156102f057610002565b33600160a060020a0390811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060016100cf56","gasEstimates":{"creation":[40354,172400],"external":{"allowance(address,address)":547,"approve(address,uint256)":22223,"balanceOf(address)":397,"totalSupply()":232,"transfer(address,uint256)":null,"transferFrom(address,address,uint256)":63271},"internal":{"safeToAdd(uint256,uint256)":52}},"functionHashes":{"allowance(address,address)":"dd62ed3e","approve(address,uint256)":"095ea7b3","balanceOf(address)":"70a08231","totalSupply()":"18160ddd","
it('should generate compiled code and abi', function() {
assert.deepEqual(compiledContracts, expectedObject);
});
});
});