aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2016-10-25 07:24:29 +0800
committerGitHub <noreply@github.com>2016-10-25 07:24:29 +0800
commitf7688ac3cf8939057013667f544d57dcb73937a5 (patch)
tree6fd725ffd0ea856c4205472557e33aa012b3b16e
parenteba37e773df54276e84d27c02a370719f670cc8b (diff)
parent3af3565000e4952d95c50c1c25a9367ba8caec90 (diff)
downloadtangerine-wallet-browser-f7688ac3cf8939057013667f544d57dcb73937a5.tar
tangerine-wallet-browser-f7688ac3cf8939057013667f544d57dcb73937a5.tar.gz
tangerine-wallet-browser-f7688ac3cf8939057013667f544d57dcb73937a5.tar.bz2
tangerine-wallet-browser-f7688ac3cf8939057013667f544d57dcb73937a5.tar.lz
tangerine-wallet-browser-f7688ac3cf8939057013667f544d57dcb73937a5.tar.xz
tangerine-wallet-browser-f7688ac3cf8939057013667f544d57dcb73937a5.tar.zst
tangerine-wallet-browser-f7688ac3cf8939057013667f544d57dcb73937a5.zip
Merge pull request #745 from MetaMask/i743-FixDelegateCallFlag
Reproduced issue 743 in test case
-rw-r--r--app/scripts/lib/idStore.js23
-rw-r--r--package.json2
-rw-r--r--test/lib/example-code.json3
-rw-r--r--test/unit/idStore-test.js21
4 files changed, 35 insertions, 14 deletions
diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js
index 9d0ca7f19..402a5e612 100644
--- a/app/scripts/lib/idStore.js
+++ b/app/scripts/lib/idStore.js
@@ -249,15 +249,9 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
if (txParams.to) {
query.getCode(txParams.to, function (err, result) {
if (err) return cb(err)
- var code = ethUtil.toBuffer(result)
- if (code !== '0x') {
- var ops = ethBinToOps(code)
- var containsDelegateCall = ops.some((op) => op.name === 'DELEGATECALL')
- txData.containsDelegateCall = containsDelegateCall
- cb()
- } else {
- cb()
- }
+ var containsDelegateCall = this.checkForDelegateCall(result)
+ txData.containsDelegateCall = containsDelegateCall
+ cb()
})
} else {
cb()
@@ -282,6 +276,17 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
}
}
+IdentityStore.prototype.checkForDelegateCall = function (codeHex) {
+ const code = ethUtil.toBuffer(codeHex)
+ if (code !== '0x') {
+ const ops = ethBinToOps(code)
+ const containsDelegateCall = ops.some((op) => op.name === 'DELEGATECALL')
+ return containsDelegateCall
+ } else {
+ return false
+ }
+}
+
IdentityStore.prototype.addGasBuffer = function (gasHex) {
var gas = new BN(gasHex, 16)
var buffer = new BN('100000', 10)
diff --git a/package.json b/package.json
index 2af0aebfc..4e1b9e73b 100644
--- a/package.json
+++ b/package.json
@@ -40,7 +40,7 @@
"dnode": "^1.2.2",
"end-of-stream": "^1.1.0",
"ensnare": "^1.0.0",
- "eth-bin-to-ops": "^1.0.0",
+ "eth-bin-to-ops": "^1.0.1",
"eth-lightwallet": "^2.3.3",
"eth-query": "^1.0.3",
"eth-store": "^1.1.0",
diff --git a/test/lib/example-code.json b/test/lib/example-code.json
new file mode 100644
index 000000000..b76d37a4c
--- /dev/null
+++ b/test/lib/example-code.json
@@ -0,0 +1,3 @@
+{
+ "delegateCallCode": "0x606060405260e060020a60003504637bd703e8811461003157806390b98a111461005c578063f8b2cb4f1461008e575b005b6100b4600435600073f28c53067227848f8145355c455da5cfdd20e3136396e4ee3d6100da84610095565b6100c660043560243533600160a060020a03166000908152602081905260408120548290101561011f57506000610189565b6100b46004355b600160a060020a0381166000908152602081905260409020545b919050565b60408051918252519081900360200190f35b604080519115158252519081900360200190f35b60026040518360e060020a02815260040180838152602001828152602001925050506020604051808303818660325a03f4156100025750506040515191506100af9050565b33600160a060020a0390811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9291505056"
+}
diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js
index 0a57d2121..da465f511 100644
--- a/test/unit/idStore-test.js
+++ b/test/unit/idStore-test.js
@@ -1,9 +1,10 @@
-var assert = require('assert')
-var IdentityStore = require('../../app/scripts/lib/idStore')
-var configManagerGen = require('../lib/mock-config-manager')
+const async = require('async')
+const assert = require('assert')
const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN
-const async = require('async')
+const configManagerGen = require('../lib/mock-config-manager')
+const delegateCallCode = require('../lib/example-code.json').delegateCallCode
+const IdentityStore = require('../../app/scripts/lib/idStore')
describe('IdentityStore', function() {
@@ -156,4 +157,16 @@ describe('IdentityStore', function() {
assert.ok(bnResult.gt(gas), 'added more gas as buffer.')
assert.equal(result.indexOf('0x'), 0, 'include hex prefix')
})
+
+ describe('#checkForDelegateCall', function() {
+ const idStore = new IdentityStore({
+ configManager: configManagerGen(),
+ ethStore: {
+ addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
+ },
+ })
+
+ var result = idStore.checkForDelegateCall(delegateCallCode)
+ assert.equal(result, true, 'no delegate call in provided code')
+ })
})