@reality.eth/reality-eth-lib 3.2.61 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -131,6 +131,9 @@ exports.bytes32ToString = function(bytes32str, qjson) {
131
131
  var bn = new BN(bytes32str, 16).fromTwos(256);
132
132
  } else if (qtype == 'uint' || qtype == 'datetime') {
133
133
  var bn = new BN(bytes32str, 16);
134
+ } else if (qtype == 'hash') {
135
+ var bn = new BN(bytes32str, 16);
136
+ return module.exports.padToBytes32(bn.toString('hex')).toLowerCase();
134
137
  } else {
135
138
  throw Error("Unrecognized answer type " + qtype);
136
139
  }
@@ -449,6 +452,9 @@ exports.getAnswerString = function(question_json, answer) {
449
452
  case 'int':
450
453
  label = module.exports.bytes32ToString(answer, question_json);
451
454
  break;
455
+ case 'hash':
456
+ label = module.exports.bytes32ToString(answer, question_json);
457
+ break;
452
458
  case 'bool':
453
459
  if (new BigNumber(answer).toNumber() === 1) {
454
460
  label = 'Yes';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reality.eth/reality-eth-lib",
3
- "version": "3.2.61",
3
+ "version": "3.3.0",
4
4
  "description": "Tools for handling questions in the reality.eth fact verification platform",
5
5
  "scripts": {
6
6
  "test": "env TZ='Asia/Kabul' mocha ./test"
@@ -16,7 +16,7 @@
16
16
  "author": "Edmund Edgar (https://reality.eth.link)",
17
17
  "license": "GPL-3.0",
18
18
  "dependencies": {
19
- "@reality.eth/contracts": "^3.0.77",
19
+ "@reality.eth/contracts": "^3.0.78",
20
20
  "bignumber.js": "^7.2.1",
21
21
  "bn.js": "^5.2.1",
22
22
  "ethereumjs-abi": "^0.6.5",
@@ -39,5 +39,5 @@
39
39
  "url": "https://github.com/RealityETH/monorepo/issues"
40
40
  },
41
41
  "homepage": "https://reality.eth.link",
42
- "gitHead": "e7c5a92f690104c2e66c03aac4adabd0d6ca70ae"
42
+ "gitHead": "1756284eb0ea7e8f51aed54b39d7c3a9caa61395"
43
43
  }
@@ -98,6 +98,19 @@ describe('Answer strings', function() {
98
98
  expect(rc_question.getAnswerString(q, '0x000000000000000000000000000000000000000000000000016345785D8A0000')).to.equal('0.1');
99
99
  expect(rc_question.getAnswerString(q, '0x0000000000000000000000000000000000000000000000001BC16D674EC80000')).to.equal('2');
100
100
  });
101
+
102
+ it('Leaves bytes32 strings unchanged except forced to lower case', function() {
103
+ // We don't have a built-in type for this yet so just switch out the uint one
104
+ var q = rc_question.populatedJSONForTemplate(rc_template.defaultTemplateForType('uint'), '');
105
+ q['type'] = 'hash';
106
+ expect(rc_question.getAnswerString(q, '0x0000000000000000000000000000000000000000000000000000000000000000')).to.equal('0x0000000000000000000000000000000000000000000000000000000000000000');
107
+ expect(rc_question.getAnswerString(q, '0x0000000000000000000000000000000000000000000000000DE0B6B3A7640000')).to.equal('0x0000000000000000000000000000000000000000000000000de0b6b3a7640000');
108
+ expect(rc_question.getAnswerString(q, '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000')).to.equal('0x0000000000000000000000000000000000000000000000000de0b6b3a7640000');
109
+ expect(rc_question.getAnswerString(q, '0x0000000000000000000000000000000000000000000000001BC16D674EC80000')).to.equal('0x0000000000000000000000000000000000000000000000001BC16D674EC80000'.toLowerCase());
110
+ expect(rc_question.getAnswerString(q, '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')).to.equal('Invalid');
111
+ });
112
+
113
+
101
114
  /*
102
115
  it('Handles ints as expected using 1 decimal', function() {
103
116
  var q = rc_question.populatedJSONForTemplate(rc_template.defaultTemplateForType('int'), '');