Skip to content

Commit

Permalink
Remove legacy POA indexing code (again) (#4633)
Browse files Browse the repository at this point in the history
  • Loading branch information
michellebrier authored Jan 21, 2023
1 parent 49baab5 commit 9409196
Show file tree
Hide file tree
Showing 24 changed files with 768 additions and 6,333 deletions.
74 changes: 0 additions & 74 deletions discovery-provider/integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from src.models.base import Base
from src.utils import helpers
from src.utils.redis_connection import get_redis
from web3 import HTTPProvider, Web3

DB_URL = os.getenv(
"audius_db_url",
Expand Down Expand Up @@ -150,79 +149,6 @@ def client(app): # pylint: disable=redefined-outer-name
return app.test_client()


def init_contracts(config):
"""
Initializes contracts given an app/celery level config and returns
deployed contract addresses.
"""
# Create web3 provider to real ganache
web3endpoint = f"http://{config['web3']['host']}:{config['web3']['port']}"
web3 = Web3(HTTPProvider(web3endpoint))

# set pre-funded account as sender
web3.eth.default_account = web3.eth.accounts[0]

registry_address = web3.toChecksumAddress(config["contracts"]["registry"])

abi_values = helpers.load_abi_values()
registry_return_val = web3.eth.contract(
address=registry_address, abi=abi_values["Registry"]["abi"]
)

# Get addresses for contracts from the registry
user_factory_address = registry_return_val.functions.getContract(
bytes("UserFactory", "utf-8")
).call()
track_factory_address = registry_return_val.functions.getContract(
bytes("TrackFactory", "utf-8")
).call()
user_replica_set_manager_address = registry_return_val.functions.getContract(
bytes("UserReplicaSetManager", "utf-8")
).call()

# Initialize contracts
user_factory_contract = web3.eth.contract(
address=user_factory_address, abi=abi_values["UserFactory"]["abi"]
)
track_factory_contract = web3.eth.contract(
address=track_factory_address, abi=abi_values["TrackFactory"]["abi"]
)
user_replica_set_manager_contract = web3.eth.contract(
address=user_replica_set_manager_address,
abi=abi_values["UserReplicaSetManager"]["abi"],
)

return {
"abi_values": abi_values,
"registry_address": registry_address,
"user_factory_address": user_factory_address,
"user_factory_contract": user_factory_contract,
"track_factory_address": track_factory_address,
"track_factory_contract": track_factory_contract,
"user_replica_set_manager_address": user_replica_set_manager_address,
"user_replica_set_manager_contract": user_replica_set_manager_contract,
"web3": web3,
}


@pytest.fixture
def contracts(app): # pylint: disable=redefined-outer-name
"""
Initializes contracts to be used with the `app` fixture
"""
return init_contracts(app.config)


@pytest.fixture
def celery_app_contracts(celery_app): # pylint: disable=redefined-outer-name
"""
Initializes contracts to be used with the `celery_app` fixture
"""
# Pull singletons off of the default first task
task = celery_app.celery.tasks["update_discovery_provider"]
return init_contracts(task.shared_config)


postgresql_my = factories.postgresql("postgresql_nooproc")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
from src.challenges.challenge_event import ChallengeEvent
from src.models.users.user import User
from src.tasks.entity_manager.entity_manager import entity_manager_update
from src.tasks.entity_manager.user import UserEventMetadata, update_user_events
from src.tasks.entity_manager.utils import TRACK_ID_OFFSET, USER_ID_OFFSET
from src.utils.db_session import get_db
from src.utils.redis_connection import get_redis
from web3 import Web3
from web3.datastructures import AttributeDict

Expand Down Expand Up @@ -711,3 +713,21 @@ def get_events_side_effect(_, tx_receipt):
assert not all_users[1].is_verified # user 2 is not verified
calls = [mock.call.dispatch(ChallengeEvent.connect_verified, 0, 1)]
bus_mock.assert_has_calls(calls, any_order=True)


@mock.patch("src.challenges.challenge_event_bus.ChallengeEventBus", autospec=True)
def test_self_referrals(bus_mock: mock.MagicMock, app):
"""Test that users can't refer themselves"""
block_hash = b"0x8f19da326900d171642af08e6770eedd83509c6c44f6855c98e6a752844e2521"
with app.app_context():
db = get_db()
redis = get_redis()
bus_mock(redis)
with db.scoped_session() as session, bus_mock.use_scoped_dispatch_queue():
user = User(user_id=1, blockhash=str(block_hash), blocknumber=1)
events: UserEventMetadata = {"referrer": 1}
update_user_events(session, user, events, bus_mock)
mock_call = mock.call.dispatch(
ChallengeEvent.referral_signup, 1, 1, {"referred_user_id": 1}
)
assert mock_call not in bus_mock.method_calls
Loading

0 comments on commit 9409196

Please sign in to comment.