Move to chainlib-eth

This commit is contained in:
nolash 2021-06-28 11:46:05 +02:00
parent 2c1b7cbb1e
commit 294ded19f5
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
9 changed files with 83 additions and 52 deletions

4
python/CHANGELOG Normal file
View File

@ -0,0 +1,4 @@
- 0.0.2-pending
* Move to chainlib-eth
- 0.0.1-unreleased
* Interface for redistributed and non-redistributed, with or without cap

View File

@ -200,7 +200,7 @@ class DemurrageTokenSimulation:
else: else:
o = self.caller_contract.balance_of(self.address, holder, sender_address=self.caller_address) o = self.caller_contract.balance_of(self.address, holder, sender_address=self.caller_address)
r = self.rpc.do(o) r = self.rpc.do(o)
return self.caller_contract.parse_balance_of(r) return self.caller_contract.parse_balance(r)
def __next_block(self): def __next_block(self):

View File

@ -14,7 +14,7 @@ from chainlib.eth.contract import (
abi_decode_single, abi_decode_single,
) )
from chainlib.eth.constant import ZERO_ADDRESS from chainlib.eth.constant import ZERO_ADDRESS
from chainlib.jsonrpc import jsonrpc_template from chainlib.jsonrpc import JSONRPCRequest
from eth_erc20 import ERC20 from eth_erc20 import ERC20
from hexathon import ( from hexathon import (
add_0x, add_0x,
@ -146,8 +146,9 @@ class DemurrageToken(ERC20):
return tx return tx
def to_base_amount(self, contract_address, value, sender_address=ZERO_ADDRESS): def to_base_amount(self, contract_address, value, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('toBaseAmount') enc.method('toBaseAmount')
@ -158,11 +159,13 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
def remainder(self, contract_address, parts, whole, sender_address=ZERO_ADDRESS): def remainder(self, contract_address, parts, whole, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('remainder') enc.method('remainder')
@ -175,11 +178,13 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
def redistributions(self, contract_address, idx, sender_address=ZERO_ADDRESS): def redistributions(self, contract_address, idx, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('redistributions') enc.method('redistributions')
@ -190,11 +195,13 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
def account_period(self, contract_address, address, sender_address=ZERO_ADDRESS): def account_period(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('accountPeriod') enc.method('accountPeriod')
@ -205,11 +212,13 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
def to_redistribution(self, contract_address, participants, demurrage_modifier_ppm, value, period, sender_address=ZERO_ADDRESS): def to_redistribution(self, contract_address, participants, demurrage_modifier_ppm, value, period, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('toRedistribution') enc.method('toRedistribution')
@ -226,12 +235,14 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
def to_redistribution_period(self, contract_address, redistribution, sender_address=ZERO_ADDRESS): def to_redistribution_period(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('toRedistributionPeriod') enc.method('toRedistributionPeriod')
@ -242,11 +253,13 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
def to_redistribution_participants(self, contract_address, redistribution, sender_address=ZERO_ADDRESS): def to_redistribution_participants(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('toRedistributionParticipants') enc.method('toRedistributionParticipants')
@ -257,11 +270,13 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
def to_redistribution_supply(self, contract_address, redistribution, sender_address=ZERO_ADDRESS): def to_redistribution_supply(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('toRedistributionSupply') enc.method('toRedistributionSupply')
@ -272,11 +287,13 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
def to_redistribution_demurrage_modifier(self, contract_address, redistribution, sender_address=ZERO_ADDRESS): def to_redistribution_demurrage_modifier(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('toRedistributionDemurrageModifier') enc.method('toRedistributionDemurrageModifier')
@ -287,11 +304,13 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
def base_balance_of(self, contract_address, address, sender_address=ZERO_ADDRESS): def base_balance_of(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('baseBalanceOf') enc.method('baseBalanceOf')
@ -302,6 +321,7 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
@ -345,8 +365,9 @@ class DemurrageToken(ERC20):
return self.call_noarg('supplyCap', contract_address, sender_address=sender_address) return self.call_noarg('supplyCap', contract_address, sender_address=sender_address)
def grow_by(self, contract_address, value, period, sender_address=ZERO_ADDRESS): def grow_by(self, contract_address, value, period, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('growBy') enc.method('growBy')
@ -359,11 +380,13 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
def decay_by(self, contract_address, value, period, sender_address=ZERO_ADDRESS): def decay_by(self, contract_address, value, period, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('decayBy') enc.method('decayBy')
@ -376,11 +399,13 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
def get_distribution(self, contract_address, supply, demurrage_amount, sender_address=ZERO_ADDRESS): def get_distribution(self, contract_address, supply, demurrage_amount, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('getDistribution') enc.method('getDistribution')
@ -393,11 +418,13 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o
def get_distribution_from_redistribution(self, contract_address, redistribution, sender_address=ZERO_ADDRESS): def get_distribution_from_redistribution(self, contract_address, redistribution, sender_address=ZERO_ADDRESS, id_generator=None):
o = jsonrpc_template() j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call' o['method'] = 'eth_call'
enc = ABIContractEncoder() enc = ABIContractEncoder()
enc.method('getDistributionFromRedistribution') enc.method('getDistributionFromRedistribution')
@ -408,6 +435,7 @@ class DemurrageToken(ERC20):
tx = self.set_code(tx, data) tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx)) o['params'].append(self.normalize(tx))
o['params'].append('latest') o['params'].append('latest')
o = j.finalize(o)
return o return o

View File

@ -1,3 +1,3 @@
chainlib~=0.0.3rc3 chainlib~=0.0.5a1
eth-erc20~=0.0.9a4 eth-erc20~=0.0.10a1
crypto-dev-signer~=0.4.14b3 crypto-dev-signer~=0.4.14b6

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = erc20-demurrage-token name = erc20-demurrage-token
version = 0.0.1b3 version = 0.0.2a1
description = ERC20 token with redistributed continual demurrage description = ERC20 token with redistributed continual demurrage
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no

View File

@ -1,3 +1,2 @@
#web3==5.12.2
eth_tester==0.5.0b3 eth_tester==0.5.0b3
py-evm==0.3.0a20 py-evm==0.3.0a20

View File

@ -35,7 +35,7 @@ class TestAmounts(TestDemurrageDefault):
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assertEqual(balance, 817) self.assertEqual(balance, 817)
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], 1000) (tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[1], 1000)
@ -43,7 +43,7 @@ class TestAmounts(TestDemurrageDefault):
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assert_within_lower(balance, 1817, 750) self.assert_within_lower(balance, 1817, 750)
self.backend.time_travel(self.start_time + self.period_seconds * 2) self.backend.time_travel(self.start_time + self.period_seconds * 2)
@ -53,7 +53,7 @@ class TestAmounts(TestDemurrageDefault):
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
expected_balance = ((1 - self.tax_level / 1000000) ** 10) * 1000 expected_balance = ((1 - self.tax_level / 1000000) ** 10) * 1000
expected_balance += ((1 - self.tax_level / 1000000) ** 20) * 1000 expected_balance += ((1 - self.tax_level / 1000000) ** 20) * 1000
@ -73,7 +73,7 @@ class TestAmounts(TestDemurrageDefault):
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assertEqual(balance, 1634) self.assertEqual(balance, 1634)
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc) nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
@ -83,12 +83,12 @@ class TestAmounts(TestDemurrageDefault):
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assertEqual(balance, 1134) self.assertEqual(balance, 1134)
o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assert_within_lower(balance, 500, 2000) self.assert_within_lower(balance, 500, 2000)
@ -115,7 +115,7 @@ class TestAmounts(TestDemurrageDefault):
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assertEqual(balance, case[1]) self.assertEqual(balance, case[1])

View File

@ -83,7 +83,7 @@ class TestRedistribution(TestDemurrageUnit):
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assertEqual(balance, expected_balance) self.assertEqual(balance, expected_balance)
@ -108,7 +108,7 @@ class TestRedistribution(TestDemurrageUnit):
for i in range(3): for i in range(3):
o = c.balance_of(self.address, self.accounts[i+1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[i+1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assertEqual(balance, expected_balance) self.assertEqual(balance, expected_balance)
@ -147,7 +147,7 @@ class TestRedistribution(TestDemurrageUnit):
expected_balance = mint_amount - demurrage_amount expected_balance = mint_amount - demurrage_amount
o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assertEqual(balance, expected_balance) self.assertEqual(balance, expected_balance)
half_demurrage_amount = int((self.tax_level / 1000000) * half_mint_amount) half_demurrage_amount = int((self.tax_level / 1000000) * half_mint_amount)
@ -155,12 +155,12 @@ class TestRedistribution(TestDemurrageUnit):
expected_balance = half_mint_amount - half_demurrage_amount expected_balance = half_mint_amount - half_demurrage_amount
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assertEqual(balance, expected_balance) self.assertEqual(balance, expected_balance)
o = c.balance_of(self.address, self.accounts[3], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[3], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assertEqual(balance, expected_balance) self.assertEqual(balance, expected_balance)
o = c.total_supply(self.address, sender_address=self.accounts[0]) o = c.total_supply(self.address, sender_address=self.accounts[0])
@ -185,7 +185,7 @@ class TestRedistribution(TestDemurrageUnit):
o = c.balance_of(self.address, self.sink_address, sender_address=self.accounts[0]) o = c.balance_of(self.address, self.sink_address, sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assert_within_lower(balance, expected_balance, 1000) self.assert_within_lower(balance, expected_balance, 1000)

View File

@ -67,18 +67,18 @@ class TestRedistributionSingle(TestDemurrageSingle):
tax_modifier = (1 - (self.tax_level / 1000000)) ** 10 tax_modifier = (1 - (self.tax_level / 1000000)) ** 10
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
self.assertEqual(balance, int(mint_amount * tax_modifier)) self.assertEqual(balance, int(mint_amount * tax_modifier))
o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
base_amount = mint_amount - int(mint_amount * 0.1) base_amount = mint_amount - int(mint_amount * 0.1)
self.assertEqual(balance, int(base_amount * tax_modifier)) #(base_amount - (base_amount * (self.tax_level / 1000000)))) self.assertEqual(balance, int(base_amount * tax_modifier)) #(base_amount - (base_amount * (self.tax_level / 1000000))))
o = c.balance_of(self.address, self.accounts[3], sender_address=self.accounts[0]) o = c.balance_of(self.address, self.accounts[3], sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
base_amount = mint_amount - int(mint_amount * 0.2) base_amount = mint_amount - int(mint_amount * 0.2)
self.assertEqual(balance, int(base_amount * tax_modifier)) #(base_amount - (base_amount * (self.tax_level / 1000000)))) self.assertEqual(balance, int(base_amount * tax_modifier)) #(base_amount - (base_amount * (self.tax_level / 1000000))))
@ -88,7 +88,7 @@ class TestRedistributionSingle(TestDemurrageSingle):
o = c.balance_of(self.address, self.sink_address, sender_address=self.accounts[0]) o = c.balance_of(self.address, self.sink_address, sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
balance = c.parse_balance_of(r) balance = c.parse_balance(r)
expected_balance = new_supply - (new_supply * tax_modifier) expected_balance = new_supply - (new_supply * tax_modifier)
self.assert_within_lower(balance, expected_balance, 1) self.assert_within_lower(balance, expected_balance, 1)