Skip to content

Commit

Permalink
test: fix failing tests for #1214
Browse files Browse the repository at this point in the history
  • Loading branch information
phra committed Dec 21, 2017
1 parent e5e89e6 commit f2c8228
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
40 changes: 18 additions & 22 deletions test/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2794,26 +2794,26 @@ describe('contract', function () {

});

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

provider.injectValidation(function (payload) {

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;

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

});
await ((async () => {
provider.injectValidation(async function (payload) {
var expected = (await 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;

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

provider.injectValidation(function (payload) {
Expand All @@ -2822,7 +2822,6 @@ describe('contract', function () {
});
provider.injectResult(null);


provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_subscribe');
assert.deepEqual(payload.params, ['newHeads']);
Expand Down Expand Up @@ -2854,7 +2853,6 @@ describe('contract', function () {
});
provider.injectResult('0x321');


var contract = new eth.Contract(abi);

contract.deploy({
Expand All @@ -2876,12 +2874,10 @@ describe('contract', function () {
})
.then(function(newContract) {
// console.log(newContract);
console.log('5')
assert.equal(newContract.options.address, address);
assert.isTrue(newContract !== contract, 'contract objects shouldn\'t the same');

setTimeout(function () {
done();
}, 1);
done();
});
// .on('error', function (value) {
// console.log('error', value);
Expand Down
12 changes: 6 additions & 6 deletions test/eth.accounts.signTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ describe("eth", function () {

// For each test
tests.forEach(function (test, i) {
it("signTransaction must compare to eth_signTransaction", function() {
it("signTransaction must compare to eth_signTransaction", async function() {
var ethAccounts = new Accounts();

var testAccount = ethAccounts.privateKeyToAccount(test.privateKey);
assert.equal(testAccount.address, test.address);

var tx = testAccount.signTransaction(test.transaction);
var tx = await testAccount.signTransaction(test.transaction);

assert.equal(tx.rawTransaction, test.rawTransaction);
});
});

tests.forEach(function (test, i) {
it("signTransaction using the iban as \"to\" must compare to eth_signTransaction", function() {
it("signTransaction using the iban as \"to\" must compare to eth_signTransaction", async function() {
var ethAccounts = new Accounts();

var testAccount = ethAccounts.privateKeyToAccount(test.privateKey);
Expand All @@ -73,7 +73,7 @@ describe("eth", function () {
var transaction = clone(test.transaction);
transaction.to = transaction.toIban;
delete transaction.toIban;
var tx = testAccount.signTransaction(transaction);
var tx = await testAccount.signTransaction(transaction);

assert.equal(tx.rawTransaction, test.rawTransaction);
});
Expand Down Expand Up @@ -207,13 +207,13 @@ describe("eth", function () {
});

tests.forEach(function (test, i) {
it("recoverTransaction, must recover signature", function() {
it("recoverTransaction, must recover signature", async function() {
var ethAccounts = new Accounts();

var testAccount = ethAccounts.privateKeyToAccount(test.privateKey);
assert.equal(testAccount.address, test.address);

var tx = testAccount.signTransaction(test.transaction);
var tx = await testAccount.signTransaction(test.transaction);
assert.equal(ethAccounts.recoverTransaction(tx.rawTransaction), test.address);
});
});
Expand Down

0 comments on commit f2c8228

Please sign in to comment.