Fixed getContractAddress function
This commit is contained in:
parent
0b59519c19
commit
4b99bb579c
2
index.js
2
index.js
@ -26,7 +26,7 @@ utils.defineProperty(exportUtils, 'sha256', utils.sha256);
|
||||
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
|
||||
utils.defineProperty(exportUtils, 'getContractAddress', function(transaction) {
|
||||
return SigningKey.getAddress('0x' + utils.sha3(rlp.encode([
|
||||
utils.hexOrBuffer(utils.getAddress(transaction.from)),
|
||||
utils.hexOrBuffer(SigningKey.getAddress(transaction.from)),
|
||||
utils.hexOrBuffer(utils.hexlify(transaction.nonce, 'nonce'))
|
||||
])).slice(12).toString('hex'));
|
||||
});
|
||||
|
@ -38,3 +38,11 @@ module.exports.testBrainWallet = require('./test-brain-wallet.js');
|
||||
// Test the solidity encoding/decoding parameters
|
||||
module.exports.testSolidityCoder = require('./test-solidity-coder.js');
|
||||
|
||||
|
||||
// Test contract address helper
|
||||
module.exports.testSolidityCoder = require('./test-contract-address.js');
|
||||
|
||||
// Test the providers API (this test case needs a little work as it
|
||||
// needs to modify the blockchain for a full test)
|
||||
//module.exports.testSolidityCoder = require('./test-providers.js');
|
||||
|
||||
|
21
tests/test-contract-address.js
Normal file
21
tests/test-contract-address.js
Normal file
@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
var Wallet = require('../index.js');
|
||||
|
||||
module.exports = function(test) {
|
||||
// Transaction: 0x939aa17985bc2a52a0c1cba9497ef09e092355a805a8150e30e24b753bac6864
|
||||
var transaction = {
|
||||
from: '0xb2682160c482eb985ec9f3e364eec0a904c44c23',
|
||||
nonce: 10,
|
||||
}
|
||||
|
||||
test.equal(
|
||||
Wallet.utils.getContractAddress(transaction),
|
||||
Wallet.getAddress('0x3474627d4f63a678266bc17171d87f8570936622'),
|
||||
'Failed to match contract address'
|
||||
)
|
||||
|
||||
test.done();
|
||||
}
|
||||
|
||||
module.exports.testSelf = module.exports;
|
||||
|
Loading…
Reference in New Issue
Block a user