2016-07-27 00:58:17 +03:00
|
|
|
'use strict';
|
|
|
|
var Wallet = require('../index.js');
|
|
|
|
|
2016-11-10 01:27:34 +03:00
|
|
|
var provider = new Wallet.providers.EtherscanProvider({testnet: true});
|
|
|
|
|
2016-07-27 00:58:17 +03:00
|
|
|
module.exports = function(test) {
|
|
|
|
var contractAddress = '0xdfaf84077cF4bCECA4F79d167F47041Ed3006D5b';
|
|
|
|
var contractABI = {
|
|
|
|
"SimpleStorage": [
|
|
|
|
{
|
|
|
|
"constant":true,
|
|
|
|
"inputs":[],
|
|
|
|
"name":"getValue",
|
2016-11-10 01:27:34 +03:00
|
|
|
"outputs":[{"name":"value","type":"string"}],
|
2016-07-27 00:58:17 +03:00
|
|
|
"type":"function"
|
|
|
|
}, {
|
|
|
|
"constant":false,
|
|
|
|
"inputs":[{"name":"value","type":"string"}],
|
|
|
|
"name":"setValue",
|
|
|
|
"outputs":[],
|
|
|
|
"type":"function"
|
|
|
|
}, {
|
|
|
|
"anonymous":false,
|
|
|
|
"inputs":[
|
|
|
|
{"indexed":false,"name":"oldValue","type":"string"},
|
|
|
|
{"indexed":false,"name":"newValue","type":"string"}
|
|
|
|
],
|
|
|
|
"name":"valueChanged",
|
|
|
|
"type":"event"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
var contractInterface = new Wallet._Contract.Interface(contractABI.SimpleStorage);
|
|
|
|
var getValue = contractInterface.getValue()
|
|
|
|
var setValue = contractInterface.setValue("foobar");
|
|
|
|
var valueChanged = contractInterface.valueChanged()
|
|
|
|
|
|
|
|
test.equal(getValue.data, '0x20965255', "wrong call data");
|
|
|
|
test.equal(setValue.data, '0x93a0935200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006666f6f6261720000000000000000000000000000000000000000000000000000', "wrong transaction data");
|
|
|
|
test.ok(
|
|
|
|
(valueChanged.topics.length === 1 && valueChanged.topics[0] === '0x68ad6719a0070b3bb2f866fa0d46c8123b18cefe9b387ddb4feb6647ca418435'),
|
|
|
|
"wrong call data"
|
|
|
|
);
|
|
|
|
|
|
|
|
// @TODO - test decode
|
|
|
|
|
|
|
|
var privateKey = new Buffer(32);
|
|
|
|
privateKey.fill(0x42);
|
|
|
|
|
2016-11-10 01:27:34 +03:00
|
|
|
var wallet = new Wallet(privateKey, provider);
|
2016-08-03 00:43:18 +03:00
|
|
|
var contract = wallet.getContract(contractAddress, contractABI.SimpleStorage);
|
|
|
|
|
2016-07-27 00:58:17 +03:00
|
|
|
function testCall() {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
contract.getValue().then(function(result) {
|
2016-11-10 01:27:34 +03:00
|
|
|
test.equal(result[0], 'test888888', 'failed to call getVaue (positional)');
|
|
|
|
test.equal(result.value, 'test888888', 'failed to call getVaue (keyword)');
|
2016-07-27 00:58:17 +03:00
|
|
|
resolve(result);
|
|
|
|
}, function(error) {
|
2016-08-02 01:36:33 +03:00
|
|
|
test.ok(false, 'failed to call getValue (is parity running on this host?)');
|
2016-07-27 00:58:17 +03:00
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:43:18 +03:00
|
|
|
function testEstimate() {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
contract.estimate.setValue('foo').then(function(result) {
|
2016-11-10 01:27:34 +03:00
|
|
|
test.equal(result.toString(16), '8f5a', 'failed to estimate setVaue');
|
2016-08-03 00:43:18 +03:00
|
|
|
resolve(result);
|
|
|
|
}, function(error) {
|
|
|
|
test.ok(false, 'failed to call getValue (is parity running on this host?)');
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-27 00:58:17 +03:00
|
|
|
Promise.all([
|
2016-08-03 00:43:18 +03:00
|
|
|
testCall(),
|
|
|
|
testEstimate(),
|
2016-07-27 00:58:17 +03:00
|
|
|
]).then(function(results) {
|
|
|
|
test.done();
|
|
|
|
}, function(error) {
|
|
|
|
console.log('ERROR', error);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-08-02 01:34:12 +03:00
|
|
|
module.exports.testSelf = module.exports;
|