Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Sep 12, 2020
1 parent 8b7697f commit 010e21e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
29 changes: 18 additions & 11 deletions lib/subproviders/geth_api_double.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,24 @@ GethApiDouble.prototype.evm_mine = function(timestamp, callback) {
// indicate that `evm_mine` only requires one argument (the callback)
GethApiDouble.prototype.evm_mine.minLength = 1;

// Unlocks any account after server start
GethApiDouble.prototype.evm_unlockUnknownAccount = function(address, callback) {
// Checks if given address is already unlocked
if (this.state.unlocked_accounts[address.toLowerCase()] !== true) {
if (this.state.personal_accounts[address.toLowerCase()] !== true) {
// Unlocks the account
this.state.unlocked_accounts[address.toLowerCase()] = true;
return callback(null, true);

} else {
// Callback if the account has been explicity locked
return callback(new Error("cannot unlock known/personal account"))
}
}
// If Account has been unlocked, this is the callback
callback(null, false);
};

GethApiDouble.prototype.debug_traceTransaction = function(txHash, params, callback) {
if (typeof params === "function") {
callback = params;
Expand All @@ -574,17 +592,6 @@ GethApiDouble.prototype.debug_traceTransaction = function(txHash, params, callba
this.state.queueTransactionTrace(txHash, params, callback);
};

// Unlocks any account after server start
GethApiDouble.prototype.debug_unlockAccount = function(address, callback) {
// Checks if given address is already unlocked
if (this.state.unlocked_accounts[address.toLowerCase()] !== true) {
// Unlocks it
this.state.unlocked_accounts[address.toLowerCase()] = true;
return callback(null, true);
}
// If Account exists, this is the callback
callback(null, "Account Already Unlocked");
};

/*
RPC AUDIT:
Expand Down
14 changes: 11 additions & 3 deletions test/forking/forking.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,19 @@ describe("Forking", function() {

it("should unlock any account after server has been started", async() => {
const address = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e";
forkedWeb3.currentProvider.send({"jsonrpc":"2.0","method":"debug_unlockAccount","params":[address],"id":42}, (err, res) => {
forkedWeb3.currentProvider.send({"jsonrpc":"2.0","method":"evm_unlockUnknownAccount","params":[address],"id":42}, (err, res) => {
assert.strictEqual(res.result, true);
});
forkedWeb3.currentProvider.send({"jsonrpc":"2.0","method":"debug_unlockAccount","params":[address],"id":42}, (err, res) => {
assert.strictEqual(res.result, "Account Already Unlocked");
forkedWeb3.currentProvider.send({"jsonrpc":"2.0","method":"evm_unlockUnknownAccount","params":[address],"id":42}, (err, res) => {
assert.strictEqual(res.result, false);
});
});

it("should not unlock any locked personal account", async() => {
const address = await mainWeb3.eth.getAccounts()[0];
await mainWeb3.eth.personal.lockAccount(address);
forkedWeb3.currentProvider.send({"jsonrpc":"2.0","method":"evm_unlockUnknownAccount","params":[address],"id":42}, (err, res) => {
assert.strictEqual(err, "cannot unlock known/personal account");
});
});

Expand Down

0 comments on commit 010e21e

Please sign in to comment.