initial steps to establish on-chain ritual access control via GlobalAllowList in tests

pull/3213/head
Kieran Prasch 2023-09-05 14:15:19 +02:00 committed by derekpierre
parent c0c77b3eb6
commit 2342f7f1ef
7 changed files with 61 additions and 22 deletions

View File

@ -725,10 +725,15 @@ class CoordinatorAgent(EthereumContractAgent):
@contract_api(TRANSACTION)
def initiate_ritual(
self, providers: List[ChecksumAddress], transacting_power: TransactingPower
self,
providers: List[ChecksumAddress],
authority: ChecksumAddress,
duration: int,
access_controller: ChecksumAddress,
transacting_power: TransactingPower,
) -> TxReceipt:
contract_function: ContractFunction = self.contract.functions.initiateRitual(
providers
providers, authority, duration, access_controller
)
receipt = self.blockchain.send_transaction(
contract_function=contract_function, transacting_power=transacting_power

View File

@ -2,12 +2,10 @@ import pytest
import pytest_twisted
from twisted.internet.threads import deferToThread
from nucypher.blockchain.eth.agents import ContractAgency, CoordinatorAgent
from nucypher.blockchain.eth.trackers.dkg import EventScannerTask
from nucypher.characters.lawful import Enrico
from nucypher.policy.conditions.lingo import ConditionLingo
from tests.acceptance.constants import APE_TEST_CHAIN_ID
from tests.constants import TEST_ETH_PROVIDER_URI
# constants
DKG_SIZE = 4
@ -28,6 +26,8 @@ CONDITIONS = {
"chain": APE_TEST_CHAIN_ID,
},
}
DURATION = 48 * 60 * 60
@pytest.fixture(scope='module')
@ -38,16 +38,10 @@ def cohort(ursulas):
return nodes
@pytest.fixture(scope='module')
def coordinator_agent(testerchain, test_registry):
"""Creates a coordinator agent"""
return ContractAgency.get_agent(
CoordinatorAgent, registry=test_registry, provider_uri=TEST_ETH_PROVIDER_URI
)
@pytest_twisted.inlineCallbacks()
def test_ursula_ritualist(testerchain, coordinator_agent, cohort, alice, bob):
def test_ursula_ritualist(
testerchain, coordinator_agent, global_allow_list, cohort, alice, bob
):
"""Tests the DKG and the encryption/decryption of a message"""
# Round 0 - Initiate the ritual
@ -57,6 +51,9 @@ def test_ursula_ritualist(testerchain, coordinator_agent, cohort, alice, bob):
cohort_staking_provider_addresses = list(u.checksum_address for u in cohort)
receipt = coordinator_agent.initiate_ritual(
providers=cohort_staking_provider_addresses,
authority=alice.transacting_power.account,
duration=DURATION,
access_controller=global_allow_list.address,
transacting_power=alice.transacting_power
)
return receipt

View File

@ -21,20 +21,20 @@ deployments:
ethereum:
local:
- contract_type: RitualToken
address: '0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C' # test account at index 0
address: '0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C' # deployer account at index 0
total_supply: 1000000000000000000000000000
- contract_type: TToken
address: '0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C' # test account at index 0
address: '0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C' # deployer account at index 0
total_supply: 1000000000000000000000000000
- contract_type: NuCypherToken
address: '0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C' # test account at index 0
address: '0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C' # deployer account at index 0
nu_token_supply: 1_000_000_000
- contract_type: StakeInfo
address: '0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C' # test account at index 0
address: '0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C' # deployer account at index 0
updaters:
- <address.0>
- contract_type: TACoApplication
address: '0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C' # test account at index 0
address: '0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C' # deployer account at index 0
t_token: <TToken.address>
threshold_staking: <ThresholdStakingForTACoApplicationMock.address>
pre_min_authorization: 40000000000000000000000
@ -42,13 +42,17 @@ deployments:
reward_duration: 604800
deauthorization_duration: 5184000
- contract_type: Coordinator
address: '0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C' # test account at index 0
address: '0x1e59ce931B4CFea3fe4B875411e280e173cB7A9C' # deployer account at index 0
stake_info: <StakeInfo.address>
ritual_timeout: 3600
max_dkg_size: 8
admin: <address.0>
currency: <RitualToken.address>
app: <TACoApplication.address>
- contract_type: GlobalAllowList
address: 0 # deployer account index
coordinator: <Coordinator.address>
admin: <address.0>
test:
mnemonic: test test test test test test test test test test test junk

View File

@ -5,7 +5,11 @@ import pytest
from web3 import Web3
from nucypher.blockchain.eth.actors import Operator, Ritualist
from nucypher.blockchain.eth.agents import ContractAgency, PREApplicationAgent
from nucypher.blockchain.eth.agents import (
ContractAgency,
CoordinatorAgent,
PREApplicationAgent,
)
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth.signers.software import Web3Signer
@ -20,6 +24,7 @@ from nucypher.utilities.logging import Logger
from tests.acceptance.constants import APE_TEST_CHAIN_ID
from tests.constants import (
BONUS_TOKENS_FOR_TESTS,
GLOBAL_ALLOW_LIST,
INSECURE_DEVELOPMENT_PASSWORD,
MOCK_STAKING_CONTRACT_NAME,
TEST_ETH_PROVIDER_URI,
@ -122,6 +127,24 @@ def threshold_staking(testerchain, test_registry):
return _threshold_staking
@pytest.fixture(scope="module", autouse=True)
def coordinator_agent(testerchain, test_registry):
"""Creates a coordinator agent"""
coordinator = ContractAgency.get_agent(
CoordinatorAgent, registry=test_registry, provider_uri=TEST_ETH_PROVIDER_URI
)
tx = coordinator.contract.functions.makeInitiationPublic().transact()
testerchain.wait_for_receipt(tx)
return coordinator
@pytest.fixture(scope="module")
def global_allow_list(testerchain, test_registry):
result = test_registry.search(contract_name=GLOBAL_ALLOW_LIST)[0]
_global_allow_list = testerchain.w3.eth.contract(address=result[2], abi=result[3])
return _global_allow_list
@pytest.fixture(scope="module")
def staking_providers(testerchain, test_registry, threshold_staking):
pre_application_agent = ContractAgency.get_agent(

View File

@ -22,6 +22,8 @@ RITUAL_TOKEN = "RitualToken"
T_TOKEN = "TToken"
STAKE_INFO = "StakeInfo"
CONDITION_NFT = "ConditionNFT"
GLOBAL_ALLOW_LIST = "GlobalAllowList"
#
# Ursula

View File

@ -32,9 +32,15 @@ def transacting_power(testerchain, alice):
)
def test_initiate_ritual(agent: CoordinatorAgent, cohort, transacting_power):
def test_initiate_ritual(
agent: CoordinatorAgent, cohort, global_allow_list, transacting_power
):
receipt = agent.initiate_ritual(
providers=cohort, transacting_power=transacting_power
providers=cohort,
authority=transacting_power.account,
duration=100,
access_controller=global_allow_list.address,
transacting_power=transacting_power,
)
participants = [

View File

@ -20,6 +20,7 @@ from nucypher.blockchain.eth.agents import (
from nucypher.blockchain.eth.registry import InMemoryContractRegistry
from tests.constants import (
CONDITION_NFT,
GLOBAL_ALLOW_LIST,
MOCK_STAKING_CONTRACT_NAME,
RITUAL_TOKEN,
STAKE_INFO,
@ -36,6 +37,7 @@ _CONTRACTS_TO_DEPLOY_ON_TESTERCHAIN = (
PREApplicationAgent.contract_name,
SubscriptionManagerAgent.contract_name,
CoordinatorAgent.contract_name,
GLOBAL_ALLOW_LIST,
CONDITION_NFT,
)