31 lines
7.5 KiB
JavaScript
31 lines
7.5 KiB
JavaScript
/*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 = {};
|
|
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"}]};
|
|
|
|
expectedObject["Token"] = {"code":"60606040526040516020806103a1833950608060405251600160a060020a033316600090815260208190526040902081905560028190555061035c806100456000396000f3606060405236156100565760e060020a6000350463095ea7b3811461005b57806318160ddd146100d457806323b872dd146100ef57806370a0823114610126578063a9059cbb1461014b578063dd62ed3e1461017f575b610002565b34610002576101b8600435602435600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b34610002576002545b60408051918252519081900360200190f35b34610002576101b8600435602435604435600160a060020a038316600090815260208190526040812054829010156101cc57610002565b3461000257600160a060020a03600435166000908152602081905260409020546100dd565b34610002576101b8600435602435600160a060020a033316600090815260208190526040812054829010156102c157610002565b34610002576100dd600435602435600160a060020a038083166000908152600160209081526040808320938516835292905220546100ce565b604080519115158252519081900360200190f35b600160a060020a03808516600090815260016020908152604080832033909416835292905220548290101561020057610002565b600160a060020a03831660009081526020819052604090205461022b90835b808201829010156100ce565b151561023657610002565b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b600160a060020a0383166000908152602081905260409020546102e4908361021f565b15156102ef57610002565b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060016100ce56","runtimeBytecode":"606060405236156100565760e060020a6000350463095ea7b3811461005b57806318160ddd146100d457806323b872dd146100ef57806370a0823114610126578063a9059cbb1461014b578063dd62ed3e1461017f575b610002565b34610002576101b8600435602435600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b34610002576002545b60408051918252519081900360200190f35b34610002576101b8600435602435604435600160a060020a038316600090815260208190526040812054829010156101cc57610002565b3461000257600160a060020a03600435166000908152602081905260409020546100dd565b34610002576101b8600435602435600160a060020a033316600090815260208190526040812054829010156102c157610002565b34610002576100dd600435602435600160a060020a038083166000908152600160209081526040808320938516835292905220546100ce565b604080519115158252519081900360200190f35b600160a060020a03808516600090815260016020908152604080832033909416835292905220548290101561020057610002565b600160a060020a03831660009081526020819052604090205461022b90835b808201829010156100ce565b151561023657610002565b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b600160a060020a0383166000908152602081905260409020546102e4908361021f565b15156102ef57610002565b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060016100ce56","gasEstimates":{"creation":[40354,172000],"external":{"allowance(address,address)":547,"approve(address,uint256)":22220,"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","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"}],"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() {
|
|
assert.deepEqual(compiledContracts, expectedObject);
|
|
});
|
|
|
|
});
|
|
|
|
});
|