-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '1.0' of github.com:ethereum/web3.js into 1.0
- Loading branch information
Showing
8 changed files
with
157 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ bower_components | |
/bower | ||
.idea/ | ||
.npm/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
var chai = require('chai'); | ||
var assert = chai.assert; | ||
var Eth = require('../packages/web3-eth'); | ||
var sha3 = require('../packages/web3-utils').sha3; | ||
var FakeIpcProvider = require('./helpers/FakeIpcProvider'); | ||
var FakeHttpProvider = require('./helpers/FakeHttpProvider'); | ||
var Promise = require('bluebird'); | ||
|
||
var abi = [ | ||
{ | ||
constant: true, | ||
inputs: [ | ||
{ | ||
name: "a", | ||
type: "bytes32" | ||
}, | ||
{ | ||
name: "b", | ||
type: "bytes32" | ||
} | ||
], | ||
name: "takesTwoBytes32", | ||
outputs: [ | ||
{ | ||
name: "", | ||
type: "bytes32" | ||
} | ||
], | ||
payable: false, | ||
type: "function", | ||
stateMutability: "view" | ||
} | ||
]; | ||
|
||
describe('contract', function () { | ||
describe('method.encodeABI', function () { | ||
it('should handle bytes32 arrays that only contain 1 byte', function () { | ||
var provider = new FakeIpcProvider(); | ||
var eth = new Eth(provider); | ||
|
||
var contract = new eth.Contract(abi); | ||
|
||
var result = contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(2)), '0x'.concat('b'.repeat(2))).encodeABI(); | ||
|
||
assert.equal(result, [ | ||
'0x1323517e', | ||
'aa00000000000000000000000000000000000000000000000000000000000000', | ||
'bb00000000000000000000000000000000000000000000000000000000000000' | ||
].join('')); | ||
}); | ||
|
||
it('should handle bytes32 arrays that are short 1 byte', function () { | ||
var provider = new FakeIpcProvider(); | ||
var eth = new Eth(provider); | ||
|
||
var contract = new eth.Contract(abi); | ||
|
||
var result = contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(62)), '0x'.concat('b'.repeat(62))).encodeABI(); | ||
|
||
assert.equal(result, [ | ||
'0x1323517e', | ||
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa00', | ||
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb00' | ||
].join('')); | ||
}); | ||
|
||
it('should throw an exception on bytes32 arrays that have an invalid length', function () { | ||
var provider = new FakeIpcProvider(); | ||
var eth = new Eth(provider); | ||
|
||
var contract = new eth.Contract(abi); | ||
|
||
var test = function () { | ||
contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(63)), '0x'.concat('b'.repeat(63))).encodeABI(); | ||
} | ||
|
||
assert.throws(test, 'Given parameter bytes has an invalid length: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"'); | ||
}); | ||
|
||
it('should handle bytes32 arrays that are full', function () { | ||
var provider = new FakeIpcProvider(); | ||
var eth = new Eth(provider); | ||
|
||
var contract = new eth.Contract(abi); | ||
|
||
var result = contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(64)), '0x'.concat('b'.repeat(64))).encodeABI(); | ||
|
||
assert.equal(result, [ | ||
'0x1323517e', | ||
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', | ||
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' | ||
].join('')); | ||
}); | ||
|
||
it('should throw an exception on bytes32 arrays that are too long', function () { | ||
var provider = new FakeIpcProvider(); | ||
var eth = new Eth(provider); | ||
|
||
var contract = new eth.Contract(abi); | ||
|
||
var test = function() { | ||
contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(66)), '0x'.concat('b'.repeat(66))).encodeABI(); | ||
} | ||
|
||
assert.throws(test, 'Given parameter bytes is too long: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"'); | ||
}); | ||
}); | ||
}); |