mirror of https://github.com/nucypher/nucypher.git
[KMS-ETH]- Revert ursula flow to depiction.
parent
5874a43d37
commit
571be97d22
|
@ -1,33 +1,84 @@
|
||||||
from nkms_eth.blockchain import TesterBlockchain
|
#!/usr/bin/env python3
|
||||||
from nkms_eth.escrow import Escrow
|
|
||||||
from nkms_eth.token import NuCypherKMSToken
|
"""Deploy contracts in tester.
|
||||||
from nkms_eth.miner import Miner
|
|
||||||
|
A simple Python script to deploy contracts and then estimate gas for different methods.
|
||||||
|
"""
|
||||||
|
import random
|
||||||
|
from nkms_eth.blockchain import project
|
||||||
|
|
||||||
|
TIMEOUT = 10
|
||||||
|
MINING_COEFF = [10 ** 5, 10 ** 7]
|
||||||
|
M = int(1e6)
|
||||||
|
NULL_ADDR = '0x' + '0' * 40
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
testerchain = TesterBlockchain()
|
proj = project()
|
||||||
|
|
||||||
print("Web3 providers -> ", testerchain.chain.web3.providers)
|
chain_name = "tester"
|
||||||
creator, *addresses = testerchain.chain.web3.eth.accounts
|
print("Make sure {} chain is running, you can connect to it, or you'll get timeout".format(chain_name))
|
||||||
# ursula, alice, *everyone_else = addresses
|
|
||||||
|
|
||||||
# Create NC ERC20 token
|
with proj.get_chain(chain_name) as chain:
|
||||||
token = NuCypherKMSToken(blockchain=testerchain)
|
web3 = chain.web3
|
||||||
|
print("Web3 providers are", web3.providers)
|
||||||
|
creator = web3.eth.accounts[0]
|
||||||
|
# ursula = web3.eth.accounts[1]
|
||||||
|
# alice = web3.eth.accounts[2]
|
||||||
|
|
||||||
# Prepare escrow and miner
|
# Create an ERC20 token
|
||||||
escrow = Escrow(blockchain=testerchain, token=token)
|
token, tx = chain.provider.get_or_deploy_contract(
|
||||||
miner = Miner(blockchain=testerchain, token=token, escrow=escrow)
|
'HumanStandardToken', deploy_args=[
|
||||||
|
int(1e9) * M, int(1e10) * M, 'NuCypher KMS', 6, 'KMS'],
|
||||||
|
deploy_transaction={
|
||||||
|
'from': creator})
|
||||||
|
chain.wait.for_receipt(tx, timeout=TIMEOUT)
|
||||||
|
print("Deployed HumanStandardToken, tx hash is", tx)
|
||||||
|
|
||||||
# Airdropping
|
escrow, tx = chain.provider.get_or_deploy_contract(
|
||||||
token._airdrop()
|
'Escrow', deploy_args=[token.address] + MINING_COEFF,
|
||||||
|
deploy_transaction={'from': creator})
|
||||||
|
chain.wait.for_receipt(tx, timeout=TIMEOUT)
|
||||||
|
print("Deployed escrow, tx hash is", tx)
|
||||||
|
|
||||||
# Locking
|
# debug airdrop
|
||||||
for address in addresses:
|
txs = [
|
||||||
miner.lock(address=address, amount=1000*NuCypherKMSToken.M, locktime=100)
|
token.transact({'from': creator}).transfer(account, 10000 * M)
|
||||||
|
for account in web3.eth.accounts[1:]]
|
||||||
|
for tx in txs:
|
||||||
|
chain.wait.for_receipt(tx, timeout=TIMEOUT)
|
||||||
|
print('Airdrop done')
|
||||||
|
|
||||||
# Select random miners
|
# Test locking
|
||||||
miners = escrow.sample()
|
for addr in web3.eth.accounts[1:]:
|
||||||
print(miners)
|
tx = token.transact({'from': addr}).approve(
|
||||||
|
escrow.address, 1000 * M)
|
||||||
|
chain.wait.for_receipt(tx, timeout=TIMEOUT)
|
||||||
|
tx = escrow.transact({'from': addr}).deposit(1000 * M, 100)
|
||||||
|
chain.wait.for_receipt(tx, timeout=TIMEOUT)
|
||||||
|
|
||||||
|
n_tokens = escrow.call().getAllLockedTokens()
|
||||||
|
print('Locked', n_tokens)
|
||||||
|
|
||||||
|
print(web3.eth.accounts[1])
|
||||||
|
print(web3.eth.accounts[-1])
|
||||||
|
address_stop, shift = escrow.call().findCumSum(NULL_ADDR, n_tokens // 3)
|
||||||
|
print(address_stop, shift)
|
||||||
|
|
||||||
|
# Experimenting with distributions of random points
|
||||||
|
n_ursulas = 5
|
||||||
|
n_select = int(n_ursulas * 1.7) # Select more ursulas
|
||||||
|
points = [0] + sorted(random.randrange(n_tokens) for _ in
|
||||||
|
range(n_select))
|
||||||
|
deltas = [i - j for i, j in zip(points[1:], points[:-1])]
|
||||||
|
addrs = set()
|
||||||
|
addr = NULL_ADDR
|
||||||
|
shift = 0
|
||||||
|
for delta in deltas:
|
||||||
|
addr, shift = escrow.call().findCumSum(addr, delta + shift)
|
||||||
|
addrs.add(addr)
|
||||||
|
addrs = random.sample(addrs, n_ursulas)
|
||||||
|
print(addrs)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue