Skip to content

Commit

Permalink
fix broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincburns committed Nov 27, 2017
1 parent dea7cfc commit 16087a0
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 91 deletions.
14 changes: 8 additions & 6 deletions packages/web3-eth-contract/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ Contract.prototype.deploy = function(options, callback){
return this._createTxObject.apply({
method: constructor,
parent: this,
deployData: options.data
deployData: options.data,
_ethAccounts: this.constructor._ethAccounts
}, options.arguments);

};
Expand Down Expand Up @@ -695,6 +696,7 @@ Contract.prototype._createTxObject = function _createTxObject(){
txObject.arguments = args || [];
txObject._method = this.method;
txObject._parent = this.parent;
txObject._ethAccounts = this.constructor._ethAccounts || this._ethAccounts;

if(this.deployData) {
txObject._deployData = this.deployData;
Expand Down Expand Up @@ -756,8 +758,8 @@ Contract.prototype._processExecuteArguments = function _processExecuteArguments(
Contract.prototype._executeMethod = function _executeMethod(){
var _this = this,
args = this._parent._processExecuteArguments.call(this, Array.prototype.slice.call(arguments), defer),
defer = promiEvent((args.type !== 'send'));

defer = promiEvent((args.type !== 'send')),
ethAccounts = _this.constructor._ethAccounts || _this._ethAccounts;

// simple return request for batch requests
if(args.generateRequest) {
Expand Down Expand Up @@ -788,7 +790,7 @@ Contract.prototype._executeMethod = function _executeMethod(){
inputFormatter: [formatters.inputCallFormatter],
outputFormatter: utils.hexToNumber,
requestManager: _this._parent._requestManager,
accounts: _this.constructor._ethAccounts, // is eth.accounts (necessary for wallet signing)
accounts: ethAccounts, // is eth.accounts (necessary for wallet signing)
defaultAccount: _this._parent.defaultAccount,
defaultBlock: _this._parent.defaultBlock
})).createFunction();
Expand All @@ -809,7 +811,7 @@ Contract.prototype._executeMethod = function _executeMethod(){
return _this._parent._decodeMethodReturn(_this._method.outputs, result);
},
requestManager: _this._parent._requestManager,
accounts: _this.constructor._ethAccounts, // is eth.accounts (necessary for wallet signing)
accounts: ethAccounts, // is eth.accounts (necessary for wallet signing)
defaultAccount: _this._parent.defaultAccount,
defaultBlock: _this._parent.defaultBlock
})).createFunction();
Expand Down Expand Up @@ -879,7 +881,7 @@ Contract.prototype._executeMethod = function _executeMethod(){
params: 1,
inputFormatter: [formatters.inputTransactionFormatter],
requestManager: _this._parent._requestManager,
accounts: _this.constructor._ethAccounts, // is eth.accounts (necessary for wallet signing)
accounts: _this.constructor._ethAccounts || _this._ethAccounts, // is eth.accounts (necessary for wallet signing)
defaultAccount: _this._parent.defaultAccount,
defaultBlock: _this._parent.defaultBlock,
extraFormatters: extraFormatters
Expand Down
172 changes: 87 additions & 85 deletions test/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2810,107 +2810,109 @@ var runTests = function(contractFactory) {

});

it('should deploy a contract, sign transaction, and return contract instance', function (done) {
var provider = new FakeIpcProvider();
var eth = new Eth(provider);
eth.accounts.wallet.add(account.privateKey);
});
}

provider.injectValidation(function (payload) {
describe('typical usage', function() {
runTests(getEthContractInstance);

var expected = eth.accounts.wallet[0].signTransaction({
data: '0x1234567000000000000000000000000'+ account.address.toLowerCase().replace('0x','') +'00000000000000000000000000000000000000000000000000000000000000c8' ,
from: account.address.toLowerCase(),
gas: '0xc350',
gasPrice: '0xbb8',
chainId: '0x1',
nonce: '0x1',
}).rawTransaction;
it('should deploy a contract, sign transaction, and return contract instance', function (done) {
var provider = new FakeIpcProvider();
var eth = new Eth(provider);
eth.accounts.wallet.add(account.privateKey);

assert.equal(payload.method, 'eth_sendRawTransaction');
assert.deepEqual(payload.params, [expected]);
provider.injectValidation(function (payload) {

});
provider.injectResult('0x5550000000000000000000000000000000000000000000000000000000000032');
var expected = eth.accounts.wallet[0].signTransaction({
data: '0x1234567000000000000000000000000' + account.address.toLowerCase().replace('0x', '') + '00000000000000000000000000000000000000000000000000000000000000c8',
from: account.address.toLowerCase(),
gas: '0xc350',
gasPrice: '0xbb8',
chainId: '0x1',
nonce: '0x1',
}).rawTransaction;

provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_getTransactionReceipt');
assert.deepEqual(payload.params, ['0x5550000000000000000000000000000000000000000000000000000000000032']);
});
provider.injectResult(null);
assert.equal(payload.method, 'eth_sendRawTransaction');
assert.deepEqual(payload.params, [expected]);

});
provider.injectResult('0x5550000000000000000000000000000000000000000000000000000000000032');

provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_subscribe');
assert.deepEqual(payload.params, ['newHeads']);
});
provider.injectResult('0x1234567');
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_getTransactionReceipt');
assert.deepEqual(payload.params, ['0x5550000000000000000000000000000000000000000000000000000000000032']);
});
provider.injectResult(null);

// fake newBlock
provider.injectNotification({
method: 'eth_subscription',
params: {
subscription: '0x1234567',
result: {
blockNumber: '0x10'
}

provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_subscribe');
assert.deepEqual(payload.params, ['newHeads']);
});
provider.injectResult('0x1234567');

// fake newBlock
provider.injectNotification({
method: 'eth_subscription',
params: {
subscription: '0x1234567',
result: {
blockNumber: '0x10'
}
});
}
});

provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_getTransactionReceipt');
assert.deepEqual(payload.params, ['0x5550000000000000000000000000000000000000000000000000000000000032']);
});
provider.injectResult({
contractAddress: addressLowercase,
blockHash: '0xffdd'
});
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_getCode');
assert.deepEqual(payload.params, [addressLowercase, 'latest']);
});
provider.injectResult('0x321');
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_getTransactionReceipt');
assert.deepEqual(payload.params, ['0x5550000000000000000000000000000000000000000000000000000000000032']);
});

provider.injectResult({
contractAddress: addressLowercase,
blockHash: '0xffdd'
});
provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_getCode');
assert.deepEqual(payload.params, [addressLowercase, 'latest']);
});
provider.injectResult('0x321');

var contract = contractFactory(abi, provider);

contract.deploy({
data: '0x1234567',
arguments: [account.address, 200]
}).send({
from: account.address,
gas: 50000,
gasPrice: 3000,
chainId: 1,
nonce: 1,
var contract = new eth.Contract(abi);

contract.deploy({
data: '0x1234567',
arguments: [account.address, 200]
}).send({
from: account.address,
gas: 50000,
gasPrice: 3000,
chainId: 1,
nonce: 1,
})
.on('transactionHash', function (value) {
assert.equal('0x5550000000000000000000000000000000000000000000000000000000000032', value);
})
.on('transactionHash', function (value) {
assert.equal('0x5550000000000000000000000000000000000000000000000000000000000032', value);
})
.on('receipt', function (receipt) {
assert.equal(address, receipt.contractAddress);
assert.isNull(contract.options.address);
})
.then(function(newContract) {
// console.log(newContract);
assert.equal(newContract.options.address, address);
assert.isTrue(newContract !== contract, 'contract objects shouldn\'t the same');

setTimeout(function () {
done();
}, 1);
});
// .on('error', function (value) {
// console.log('error', value);
// done();
// });
.on('receipt', function (receipt) {
assert.equal(address, receipt.contractAddress);
assert.isNull(contract.options.address);
})
.then(function (newContract) {
// console.log(newContract);
assert.equal(newContract.options.address, address);
assert.isTrue(newContract !== contract, 'contract objects shouldn\'t the same');

}).timeout(4000);
// TODO add error check
});
}
setTimeout(function () {
done();
}, 1);
});
// .on('error', function (value) {
// console.log('error', value);
// done();
// });

describe('typical usage', function() {
runTests(getEthContractInstance);
}).timeout(4000);
// TODO add error check
});

describe('standalone usage', function() {
Expand Down

0 comments on commit 16087a0

Please sign in to comment.