mirror of
git://holbrook.no/erc20-demurrage-token
synced 2024-11-15 14:06:45 +01:00
Add total burned method
This commit is contained in:
parent
90fb95208f
commit
140dde7bc3
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -167,6 +167,21 @@ class DemurrageToken(ERC20):
|
||||
return tx
|
||||
|
||||
|
||||
def total_burned(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||
j = JSONRPCRequest(id_generator)
|
||||
o = j.template()
|
||||
o['method'] = 'eth_call'
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('totalBurned')
|
||||
data = add_0x(enc.get())
|
||||
tx = self.template(sender_address, contract_address)
|
||||
tx = self.set_code(tx, data)
|
||||
o['params'].append(self.normalize(tx))
|
||||
o['params'].append('latest')
|
||||
o = j.finalize(o)
|
||||
return o
|
||||
|
||||
|
||||
def to_base_amount(self, contract_address, value, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||
j = JSONRPCRequest(id_generator)
|
||||
o = j.template()
|
||||
@ -538,6 +553,7 @@ class DemurrageToken(ERC20):
|
||||
def parse_supply_cap(self, v):
|
||||
return abi_decode_single(ABIContractType.UINT256, v)
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_grow_by(self, v):
|
||||
return abi_decode_single(ABIContractType.UINT256, v)
|
||||
@ -561,3 +577,8 @@ class DemurrageToken(ERC20):
|
||||
@classmethod
|
||||
def parse_resolution_factor(self, v):
|
||||
return abi_decode_single(ABIContractType.UINT256, v)
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_total_burned(self, v):
|
||||
return abi_decode_single(ABIContractType.UINT256, v)
|
||||
|
@ -37,7 +37,7 @@ class TestBurn(TestDemurrageDefault):
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
|
||||
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash, o) = c.burn(self.address, self.accounts[1], 500000)
|
||||
(tx_hash, o) = c.burn(self.address, self.accounts[1], 600000)
|
||||
r = self.rpc.do(o)
|
||||
o = receipt(tx_hash)
|
||||
r = self.rpc.do(o)
|
||||
@ -50,7 +50,7 @@ class TestBurn(TestDemurrageDefault):
|
||||
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
|
||||
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash, o) = c.burn(self.address, self.accounts[1], 500000)
|
||||
(tx_hash, o) = c.burn(self.address, self.accounts[1], 600000)
|
||||
r = self.rpc.do(o)
|
||||
o = receipt(tx_hash)
|
||||
r = self.rpc.do(o)
|
||||
@ -59,7 +59,12 @@ class TestBurn(TestDemurrageDefault):
|
||||
o = c.total_supply(self.address, sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
new_supply = c.parse_total_supply(r)
|
||||
self.assertEqual(new_supply, 500000)
|
||||
self.assertEqual(new_supply, 400000)
|
||||
|
||||
o = c.total_burned(self.address, sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
burned = c.parse_total_burned(r)
|
||||
self.assertEqual(burned, 600000)
|
||||
|
||||
|
||||
def test_burned_redistribution(self):
|
||||
|
@ -509,6 +509,11 @@ contract DemurrageTokenSingleCap {
|
||||
return supply - burned;
|
||||
}
|
||||
|
||||
// Return total number of burned tokens
|
||||
function totalBurned() public view returns (uint256) {
|
||||
return burned;
|
||||
}
|
||||
|
||||
// Implements EIP165
|
||||
function supportsInterface(bytes4 _sum) public pure returns (bool) {
|
||||
if (_sum == 0xc6bb4b70) { // ERC20
|
||||
|
Loading…
Reference in New Issue
Block a user