mirror of https://github.com/nucypher/nucypher.git
Carving out worklock agent tests.
parent
cdc8696855
commit
496f73680a
|
@ -954,12 +954,14 @@ class WorkLockAgent(EthereumContractAgent):
|
||||||
|
|
||||||
registry_contract_name = "WorkLock"
|
registry_contract_name = "WorkLock"
|
||||||
|
|
||||||
def bid(self, amount: int, sender_address: str) -> dict:
|
def bid(self, eth_amount: int, sender_address: str) -> dict:
|
||||||
"""
|
"""
|
||||||
Bid for tokens with ETH.
|
Bid for tokens with ETH.
|
||||||
"""
|
"""
|
||||||
contract_function = self.contract.functions.bid({'value': amount})
|
contract_function = self.contract.functions.bid()
|
||||||
receipt = self.blockchain.send_transaction(contract_function=contract_function, sender_address=sender_address)
|
receipt = self.blockchain.send_transaction(contract_function=contract_function,
|
||||||
|
sender_address=sender_address,
|
||||||
|
payload={'value': eth_amount})
|
||||||
return receipt
|
return receipt
|
||||||
|
|
||||||
def claim(self, sender_address: str) -> dict:
|
def claim(self, sender_address: str) -> dict:
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
import pytest
|
||||||
|
from web3 import Web3
|
||||||
|
|
||||||
|
from nucypher.blockchain.eth.agents import WorkLockAgent, ContractAgency
|
||||||
|
from nucypher.blockchain.eth.deployers import WorkLockDeployer
|
||||||
|
from nucypher.blockchain.eth.token import NU
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module", autouse=True)
|
||||||
|
def deploy_worklock(testerchain, agency, test_registry, token_economics):
|
||||||
|
|
||||||
|
# TODO: Move to "WorkLockEconomics" class #1126
|
||||||
|
now = testerchain.w3.eth.getBlock(block_identifier='latest').timestamp
|
||||||
|
start_bid_date = now + (60 * 60) # 1 Hour
|
||||||
|
end_bid_date = start_bid_date + (60 * 60)
|
||||||
|
deposit_rate = 100
|
||||||
|
refund_rate = 200
|
||||||
|
locked_periods = 2 * token_economics.minimum_locked_periods
|
||||||
|
|
||||||
|
# Deploy
|
||||||
|
deployer = WorkLockDeployer(registry=test_registry,
|
||||||
|
deployer_address=testerchain.etherbase_account,
|
||||||
|
start_date=start_bid_date,
|
||||||
|
end_date=end_bid_date,
|
||||||
|
refund_rate=refund_rate,
|
||||||
|
deposit_rate=deposit_rate,
|
||||||
|
locked_periods=locked_periods)
|
||||||
|
_deployment_receipts = deployer.deploy()
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_worklock_agent(testerchain, test_registry, agency, token_economics, deploy_worklock):
|
||||||
|
agent = WorkLockAgent(registry=test_registry)
|
||||||
|
assert agent.contract_address
|
||||||
|
same_agent = ContractAgency.get_agent(WorkLockAgent, registry=test_registry)
|
||||||
|
assert agent == same_agent
|
||||||
|
|
||||||
|
|
||||||
|
def test_bid(testerchain, agency, token_economics, test_registry):
|
||||||
|
agent = ContractAgency.get_agent(WorkLockAgent, registry=test_registry)
|
||||||
|
big_bidder = testerchain.unassigned_accounts[-1]
|
||||||
|
receipt = agent.bid(sender_address=big_bidder,
|
||||||
|
eth_amount=int(Web3.fromWei(1, 'ether')))
|
||||||
|
assert receipt
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_remaining_work(testerchain, agency, token_economics, test_registry):
|
||||||
|
agent = ContractAgency.get_agent(WorkLockAgent, registry=test_registry)
|
||||||
|
bidder = testerchain.unassigned_accounts[-1]
|
||||||
|
receipt = agent.get_remaining_work(target_address=bidder)
|
||||||
|
assert receipt
|
||||||
|
|
||||||
|
|
||||||
|
def test_claim(testerchain, agency, token_economics, test_registry):
|
||||||
|
agent = ContractAgency.get_agent(WorkLockAgent, registry=test_registry)
|
||||||
|
bidder = testerchain.unassigned_accounts[-1]
|
||||||
|
receipt = agent.claim(sender_address=bidder)
|
||||||
|
assert receipt
|
||||||
|
|
||||||
|
|
||||||
|
def test_refund(testerchain, agency, token_economics, test_registry):
|
||||||
|
agent = ContractAgency.get_agent(WorkLockAgent, registry=test_registry)
|
||||||
|
bidder = testerchain.unassigned_accounts[-1]
|
||||||
|
receipt = agent.refund(sender_address=bidder)
|
||||||
|
assert receipt
|
||||||
|
|
|
@ -19,20 +19,20 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
||||||
import pytest
|
import pytest
|
||||||
from eth_utils import is_checksum_address
|
from eth_utils import is_checksum_address
|
||||||
|
|
||||||
from nucypher.blockchain.eth.agents import NucypherTokenAgent, WorkLockAgent
|
from nucypher.blockchain.eth.agents import WorkLockAgent
|
||||||
from nucypher.blockchain.eth.deployers import NucypherTokenDeployer, WorkLockDeployer
|
from nucypher.blockchain.eth.deployers import WorklockDeployer
|
||||||
from nucypher.blockchain.eth.interfaces import EthereumContractRegistry
|
from nucypher.blockchain.eth.registry import BaseContractRegistry
|
||||||
|
|
||||||
|
|
||||||
def test_token_deployer_and_agent(testerchain, agency, token_economics):
|
def test_token_deployer(testerchain, test_registry, agency, token_economics):
|
||||||
origin = testerchain.etherbase_account
|
origin = testerchain.etherbase_account
|
||||||
|
|
||||||
# Trying to get token from blockchain before it's been published fails
|
# Trying to get token from blockchain before it's been published fails
|
||||||
with pytest.raises(EthereumContractRegistry.UnknownContract):
|
with pytest.raises(BaseContractRegistry.UnknownContract):
|
||||||
WorkLockAgent(blockchain=testerchain)
|
WorkLockAgent(registry=test_registry)
|
||||||
|
|
||||||
# Generate WorkLock params
|
# Generate WorkLock params
|
||||||
# TODO: Move to "economics" class?
|
# TODO: Move to "WorkLockEconomics" class #1126
|
||||||
now = testerchain.w3.eth.getBlock(block_identifier='latest').timestamp
|
now = testerchain.w3.eth.getBlock(block_identifier='latest').timestamp
|
||||||
start_bid_date = now + (60 * 60) # 1 Hour
|
start_bid_date = now + (60 * 60) # 1 Hour
|
||||||
end_bid_date = start_bid_date + (60 * 60)
|
end_bid_date = start_bid_date + (60 * 60)
|
||||||
|
@ -41,7 +41,7 @@ def test_token_deployer_and_agent(testerchain, agency, token_economics):
|
||||||
locked_periods = 2 * token_economics.minimum_locked_periods
|
locked_periods = 2 * token_economics.minimum_locked_periods
|
||||||
|
|
||||||
# Create WorkLock Deployer
|
# Create WorkLock Deployer
|
||||||
deployer = WorkLockDeployer(blockchain=testerchain,
|
deployer = WorklockDeployer(blockchain=testerchain,
|
||||||
deployer_address=origin,
|
deployer_address=origin,
|
||||||
start_date=start_bid_date,
|
start_date=start_bid_date,
|
||||||
end_date=end_bid_date,
|
end_date=end_bid_date,
|
||||||
|
|
Loading…
Reference in New Issue