You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.0 KiB
106 lines
3.0 KiB
var chai = require('chai');
|
|
var assert = require('assert');
|
|
var abi = require('../lib/solidity/abi');
|
|
|
|
describe('lib/solidity/abi', function () {
|
|
describe('formatConstructorParams', function () {
|
|
it('should format uint256 properly', function () {
|
|
// given
|
|
var description = [{
|
|
"name": "test",
|
|
"type": "constructor",
|
|
"inputs": [{
|
|
"name": "a",
|
|
"type": "uint256"
|
|
}
|
|
]
|
|
}];
|
|
|
|
// when
|
|
var bytes = abi.formatConstructorParams(description, [2]);
|
|
|
|
// then
|
|
assert.equal(bytes, '0000000000000000000000000000000000000000000000000000000000000002');
|
|
});
|
|
|
|
it('should not find matching constructor', function () {
|
|
// given
|
|
var description = [{
|
|
"name": "test",
|
|
"type": "constructor",
|
|
"inputs": [{
|
|
"name": "a",
|
|
"type": "uint256"
|
|
}
|
|
]
|
|
}];
|
|
|
|
// when
|
|
var bytes = abi.formatConstructorParams(description, []);
|
|
|
|
// then
|
|
assert.equal(bytes, '');
|
|
});
|
|
|
|
it('should not find matching constructor2', function () {
|
|
// given
|
|
var description = [{
|
|
"name": "test",
|
|
"type": "constructor",
|
|
"inputs": [{
|
|
"name": "a",
|
|
"type": "uint256"
|
|
}
|
|
]
|
|
}];
|
|
|
|
// when
|
|
var bytes = abi.formatConstructorParams(description, [1,2]);
|
|
|
|
// then
|
|
assert.equal(bytes, '');
|
|
});
|
|
|
|
it('should not find matching constructor3', function () {
|
|
// given
|
|
var description = [{
|
|
"name": "test",
|
|
"type": "function",
|
|
"inputs": [{
|
|
"name": "a",
|
|
"type": "uint256"
|
|
}
|
|
]
|
|
}];
|
|
|
|
// when
|
|
var bytes = abi.formatConstructorParams(description, [2]);
|
|
|
|
// then
|
|
assert.equal(bytes, '');
|
|
});
|
|
|
|
it('should find matching constructor with multiple args', function () {
|
|
// given
|
|
var description = [{
|
|
"name": "test",
|
|
"type": "constructor",
|
|
"inputs": [{
|
|
"name": "a",
|
|
"type": "uint256"
|
|
}, {
|
|
"name": "b",
|
|
"type": "uint256"
|
|
}]
|
|
}];
|
|
|
|
// when
|
|
var bytes = abi.formatConstructorParams(description, ['1', '5']);
|
|
|
|
// then
|
|
assert.equal(bytes, '00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000005');
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
|