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

Commit

Permalink
run automatic formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmurdoch committed Sep 15, 2020
1 parent a7e36c1 commit 996e49d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
19 changes: 9 additions & 10 deletions lib/subproviders/geth_api_double.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,12 @@ GethApiDouble.prototype.evm_mine.minLength = 1;

/**
* Unlocks any unknown account.
*
*
* Note: accounts known to the `personal` namespace and accounts returned by
* `eth_accounts` cannot be unlocked using this method.
*
*
* @param {*} address the address of the account to unlock
* @param {*} callback
* @param {*} callback
* @returns `true` if the account was unlocked successfully, `false` if the
* account was already unlocked. Throws an error if the account could not be
* unlocked.
Expand All @@ -585,11 +585,10 @@ GethApiDouble.prototype.evm_unlockUnknownAccount = function(address, callback) {
// unlock the account
this.state.unlocked_accounts[address] = true;
return callback(null, true);

} else {
// if the account is known to the `personal` namespace we may not unlock
// it
return callback(new Error("cannot unlock known/personal account"))
return callback(new Error("cannot unlock known/personal account"));
}
}
// account was already unlocked, return `false`
Expand All @@ -598,12 +597,12 @@ GethApiDouble.prototype.evm_unlockUnknownAccount = function(address, callback) {

/**
* Locks any unknown account.
*
*
* Note: accounts known to the `personal` namespace and accounts returned by
* `eth_accounts` cannot be locked using this method.
*
*
* @param {*} address the address of the account to lock
* @param {*} callback
* @param {*} callback
* @returns `true` if the account was locked successfully, `false` if the
* account was already locked. Throws an error if the account could not be
* locked.
Expand All @@ -614,7 +613,7 @@ GethApiDouble.prototype.evm_lockUnknownAccount = function(address, callback) {
if (this.state.unlocked_accounts[address]) {
if (this.state.personal_accounts[address]) {
// if the account is known to the `personal` namespace we may not lock it
return callback(new Error("cannot lock known/personal account"))
return callback(new Error("cannot lock known/personal account"));
} else {
// unlock the account
delete this.state.unlocked_accounts[address];
Expand All @@ -623,7 +622,7 @@ GethApiDouble.prototype.evm_lockUnknownAccount = function(address, callback) {
}
// account wasn't locked to begin with, return `false`
callback(null, false);
}
};

GethApiDouble.prototype.debug_traceTransaction = function(txHash, params, callback) {
if (typeof params === "function") {
Expand Down
53 changes: 28 additions & 25 deletions test/local/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,62 +287,65 @@ describe("Accounts", () => {
});

describe("evm_lockUnknownAccount/evm_unlockUnknownAccount", () => {
let accounts, web3, send;
before(async ()=>{
let accounts, send;
before(async() => {
const context = await initializeTestProvider();
accounts = context.accounts;
web3 = context.web3;
send = context.send;
});

it("should unlock any account after server has been started", async () => {
it("should unlock any account after server has been started", async() => {
const address = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e";
const {result: result1} = await send("evm_unlockUnknownAccount", address);
const { result: result1 } = await send("evm_unlockUnknownAccount", address);
assert.strictEqual(result1, true);

// should return `false` if account was already locked
const {result: result2} = await send("evm_unlockUnknownAccount", address);
const { result: result2 } = await send("evm_unlockUnknownAccount", address);
assert.strictEqual(result2, false);
});
it("should not unlock any locked personal account", async () => {

it("should not unlock any locked personal account", async() => {
const [address] = accounts;
await send("personal_lockAccount", address);
try {
await assert.rejects(send("evm_unlockUnknownAccount", {
message: "cannot unlock known/personal account"
}));
await assert.rejects(
send("evm_unlockUnknownAccount", {
message: "cannot unlock known/personal account"
})
);
} finally {
// unlock the account
await send("personal_unlockAccount", address, "", 0);
}
});

it("should lock any unlocked unknown account via evm_lockUnknownAccount", async () => {
it("should lock any unlocked unknown account via evm_lockUnknownAccount", async() => {
const address = "0x842d35Cc6634C0532925a3b844Bc454e4438f44f";
const {result: unlockResult} = await send("evm_unlockUnknownAccount", address);
const { result: unlockResult } = await send("evm_unlockUnknownAccount", address);
assert.strictEqual(unlockResult, true);

const {result: lockResult1} = await send("evm_lockUnknownAccount", address);
const { result: lockResult1 } = await send("evm_lockUnknownAccount", address);
assert.strictEqual(lockResult1, true);

// bonus: also make sure we return false when the account is already locked:
const {result: lockResult2} = await send("evm_lockUnknownAccount", address);
const { result: lockResult2 } = await send("evm_lockUnknownAccount", address);
assert.strictEqual(lockResult2, false);
});

it("should not lock a known account via evm_lockUnknownAccount", async () => {
await assert.rejects(send("evm_lockUnknownAccount", accounts[0], {
message: "cannot lock known/personal account"
}));
it("should not lock a known account via evm_lockUnknownAccount", async() => {
await assert.rejects(
send("evm_lockUnknownAccount", accounts[0], {
message: "cannot lock known/personal account"
})
);
});

it("should not lock a personal account via evm_lockUnknownAccount", async () => {
it("should not lock a personal account via evm_lockUnknownAccount", async() => {
// create a new personal account
const {result: address} = await send("personal_newAccount","password");
const { result: address } = await send("personal_newAccount", "password");

// then explicitly unlock it
const {result} = await send("personal_unlockAccount", address, "password", 0);
const { result } = await send("personal_unlockAccount", address, "password", 0);
assert.strictEqual(result, true);

// then try to lock it via evm_lockUnknownAccount
Expand All @@ -351,9 +354,9 @@ describe("Accounts", () => {
});
});

it("should return `false` upon lock if account isn't locked (unknown account)", async () => {
it("should return `false` upon lock if account isn't locked (unknown account)", async() => {
const address = "0x942d35Cc6634C0532925a3b844Bc454e4438f450";
const {result} = await send("evm_lockUnknownAccount", address);
const { result } = await send("evm_lockUnknownAccount", address);
assert.strictEqual(result, false);
});
});
Expand Down
1 change: 0 additions & 1 deletion test/local/forking/forking.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ describe("Forking", function() {
assert.strictEqual(mainWeb3.utils.hexToNumber(result), 5);
});


it("should execute calls against a contract on the forked provider via the main provider", async() => {
var example = new mainWeb3.eth.Contract(contract.abi, contractAddress);

Expand Down

0 comments on commit 996e49d

Please sign in to comment.