question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testing: Impersonate Account API

See original GitHub issue

Overview

  • Currently, mainnet-fork capabilities are limited by not having a way to unlock accounts. We should add a method to the TestProviderAPI for unlocking accounts.

I am trying to make my tests have accounts that start off with ERC20s.

Specification

class TestProviderAPI:
    def impersonate_account(self, address):
        raise NotImplementedError(...)  # Override if this feature is supported

Dependencies

Include links to any open issues that must be resolved before this feature can be implemented.

Will also require updating Hardhat plugin

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
unparalleled-jscommented, Feb 10, 2022

Yes, I think that all makes sense and works out nicely.

So would this be a usage example?

@pytest.fixture
def account_with_dai(accounts, chain):
    dev_account = accounts[0]
    impersonated_account = chain.impersonate_account("0xwhatever")
    impersonated_account.transfer(dev_account, "100 DAI")
    return dev_account
0reactions
fubuloubucommented, Mar 20, 2022

Also have config-driven impersonated accounts, something like :

test:
    unlocked_accounts:
      - name: DaiHolder
         address: 0x12..45

Also, change the accounts test fixture to include key-accessible unlocked accounts:

def test_accounts(accounts):
    acct = accounts[0]
    dai_acct = accounts["DaiHolder"] 

I think this type of feature fits better with #306

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test that you login as a user (impersonate) | Acronis Cyber ...
Get started with Test that you login as a user (impersonate), Acronis Account Management by Acronis Cyber Platform on the Postman Public API...
Read more >
Impersonate a user while calling an API - Auth0 Community
Hi Auth0 Team,. I was trying to hind out how I can impersonate a user while calling or unit testing an API end...
Read more >
Test Security Settings by Impersonation - LabKey Support
Impersonating a user is useful for testing a specific user's permissions or assisting a user having trouble on the site. Select (User) >...
Read more >
C# - Asp.net web API test project - how to impersonate a user ...
I am now running my test cases using SimpleImpersonation library. This nugget package allows you to impersonate some user and its really ...
Read more >
How can I impersonate a user in the REST API? - ServiceNow
I have a service type login for the API running on a back end system. I would like ot know if a particular...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found