31 lines
7.2 KiB
JavaScript
31 lines
7.2 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":"6060604052604051602080607d83395060806040525160008190555060568060276000396000f3606060405260e060020a60003504632a1afcd98114602e57806360fe47b11460365780636d4ce63c146040575b005b604460005481565b600435600055602c565b6000545b60408051918252519081900360200190f3","runtimeBytecode":"606060405260e060020a60003504632a1afcd98114602e57806360fe47b11460365780636d4ce63c146040575b005b604460005481565b600435600055602c565b6000545b60408051918252519081900360200190f3","gasEstimates":{"creation":[20097,17200],"external":{"get()":221,"set(uint256)":20121,"storedData()":191},"internal":{}},"functionHashes":{"get()":"6d4ce63c","set(uint256)":"60fe47b1","storedData()":"2a1afcd9"},"abiDefinition":[{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}]};
|
||
|
|
||
|
expectedObject["Token"] = {"code":"6060604052604051602080610382833950608060405251600160a060020a033316600090815260208190526040902081905560028190555061033d806100456000396000f3606060405236156100565760e060020a6000350463095ea7b3811461005857806318160ddd146100cd57806323b872dd146100e357806370a0823114610115578063a9059cbb14610135578063dd62ed3e14610164575b005b61019860043560243533600160a060020a03908116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b60408051918252519081900360200190f35b610198600435602435604435600160a060020a038316600090815260208190526040812054829010156101ac57610002565b600160a060020a03600435166000908152602081905260409020546100d1565b61019860043560243533600160a060020a0316600090815260208190526040812054829010156102a157610002565b6100d1600435602435600160a060020a038281166000908152600160209081526040808320938516835292905220546100c7565b604080519115158252519081900360200190f35b600160a060020a0384811660009081526001602090815260408083203390941683529290522054829010156101e057610002565b600160a060020a03831660009081526020819052604090205461020b90835b818101829010156100c7565b151561021657610002565b600160a060020a038481166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b600160a060020a0383166000908152602081905260409020546102c490836101ff565b15156102cf57610002565b33600160a060020a0390811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060016100c756","runtimeBytecode":"606060405236156100565760e060020a6000350463095ea7b3811461005857806318160ddd146100cd57806323b872dd146100e357806370a0823114610115578063a9059cbb14610135578063dd62ed3e14610164575b005b61019860043560243533600160a060020a03908116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b60408051918252519081900360200190f35b610198600435602435604435600160a060020a038316600090815260208190526040812054829010156101ac57610002565b600160a060020a03600435166000908152602081905260409020546100d1565b61019860043560243533600160a060020a0316600090815260208190526040812054829010156102a157610002565b6100d1600435602435600160a060020a038281166000908152600160209081526040808320938516835292905220546100c7565b604080519115158252519081900360200190f35b600160a060020a0384811660009081526001602090815260408083203390941683529290522054829010156101e057610002565b600160a060020a03831660009081526020819052604090205461020b90835b818101829010156100c7565b151561021657610002565b600160a060020a038481166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b600160a060020a0383166000908152602081905260409020546102c490836101ff565b15156102cf57610002565b33600160a060020a0390811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060016100c756","gasEstimates":{"creation":[40348,165800],"external":{"allowance(address,address)":532,"approve(address,uint256)":22208,"balanceOf(address)":382,"totalSupply()":217,"transfer(address,uint256)":null,"transferFrom(address,address,uint256)":63256},"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
|
||
|
|
||
|
it('should generate compiled code and abi', function() {
|
||
|
assert.deepEqual(compiledContracts, expectedObject);
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
});
|