Add period to account word
This commit is contained in:
parent
68a7e3e1db
commit
64a6bdcabe
@ -56,14 +56,12 @@ class Test(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@unittest.skip('foo')
|
|
||||||
def test_period(self):
|
def test_period(self):
|
||||||
self.assertEqual(self.contract.functions.actualPeriod().call(), 0)
|
self.assertEqual(self.contract.functions.actualPeriod().call(), 0)
|
||||||
self.eth_tester.mine_blocks(PERIOD)
|
self.eth_tester.mine_blocks(PERIOD)
|
||||||
self.assertEqual(self.contract.functions.actualPeriod().call(), 1)
|
self.assertEqual(self.contract.functions.actualPeriod().call(), 1)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skip('foo')
|
|
||||||
def test_mint(self):
|
def test_mint(self):
|
||||||
tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[1], 1024).transact();
|
tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[1], 1024).transact();
|
||||||
r = self.w3.eth.getTransactionReceipt(tx_hash);
|
r = self.w3.eth.getTransactionReceipt(tx_hash);
|
||||||
@ -96,7 +94,6 @@ class Test(unittest.TestCase):
|
|||||||
self.assertEqual(balance_bob, 500);
|
self.assertEqual(balance_bob, 500);
|
||||||
|
|
||||||
|
|
||||||
@unittest.skip('foo')
|
|
||||||
def test_apply_tax(self):
|
def test_apply_tax(self):
|
||||||
self.eth_tester.mine_blocks(PERIOD)
|
self.eth_tester.mine_blocks(PERIOD)
|
||||||
tx_hash = self.contract.functions.applyTax().transact()
|
tx_hash = self.contract.functions.applyTax().transact()
|
||||||
@ -111,7 +108,6 @@ class Test(unittest.TestCase):
|
|||||||
self.assertEqual(self.contract.functions.demurrageModifier().call(), 960400)
|
self.assertEqual(self.contract.functions.demurrageModifier().call(), 960400)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skip('foo')
|
|
||||||
def test_tax_balance(self):
|
def test_tax_balance(self):
|
||||||
tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[1], 1000).transact()
|
tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[1], 1000).transact()
|
||||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||||
@ -153,6 +149,19 @@ class Test(unittest.TestCase):
|
|||||||
self.assertEqual(balance_bob_trunc, 500000)
|
self.assertEqual(balance_bob_trunc, 500000)
|
||||||
|
|
||||||
|
|
||||||
|
def test_period(self):
|
||||||
|
tx_hash = self.contract.functions.mintTo(self.w3.eth.accounts[1], 1024).transact();
|
||||||
|
r = self.w3.eth.getTransactionReceipt(tx_hash);
|
||||||
|
self.assertEqual(r.status, 1);
|
||||||
|
|
||||||
|
self.eth_tester.mine_blocks(PERIOD*10)
|
||||||
|
|
||||||
|
tx_hash = self.contract.functions.transfer(self.w3.eth.accounts[2], 500).transact({'from': self.w3.eth.accounts[1]});
|
||||||
|
r = self.w3.eth.getTransactionReceipt(tx_hash);
|
||||||
|
self.assertEqual(r.status, 1);
|
||||||
|
|
||||||
|
period = self.contract.functions.accountPeriod(self.w3.eth.accounts[1]).call();
|
||||||
|
self.assertEqual(period, 11);
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -122,17 +122,39 @@ contract RedistributedDemurrageToken {
|
|||||||
return demurrageModifier;
|
return demurrageModifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
function transfer(address _to, uint256 _value) public returns (bool ) {
|
function accountPeriod(address _account) public returns (uint256) {
|
||||||
//&uint256 baseValue = (_value * 1000000) / demurrageModifier;
|
return (uint256(account[_account]) & 0xffffffffffffffffffffffff0000000000000000000000000000000000000000) >> 160;
|
||||||
uint256 baseValue = (_value * 1000000) / demurrageModifier;
|
}
|
||||||
bool result = transferBase(_to, baseValue);
|
|
||||||
|
function saveAccountPeriod(address _account, uint256 _period) private returns (bool) {
|
||||||
|
account[_account] &= 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff;
|
||||||
|
account[_account] |= bytes32(_period << 160);
|
||||||
|
}
|
||||||
|
|
||||||
|
function transfer(address _to, uint256 _value) public returns (bool) {
|
||||||
|
// TODO: Prefer to truncate the result, instead it seems to round to nearest :/
|
||||||
|
uint256 baseValue;
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
baseValue = (_value * 1000000) / demurrageModifier;
|
||||||
|
result = transferBase(msg.sender, _to, baseValue);
|
||||||
emit Transfer(msg.sender, _to, _value);
|
emit Transfer(msg.sender, _to, _value);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function transferBase(address _to, uint256 _value) private returns (bool) {
|
function transferBase(address _from, address _to, uint256 _value) private returns (bool) {
|
||||||
decreaseBalance(msg.sender, _value);
|
uint256 period;
|
||||||
increaseBalance(_to, _value);
|
|
||||||
|
if (!decreaseBalance(msg.sender, _value)) {
|
||||||
|
revert('ERR_TX_DECREASEBALANCE');
|
||||||
|
}
|
||||||
|
if (!increaseBalance(_to, _value)) {
|
||||||
|
revert('ERR_TX_INCREASEBALANCE');
|
||||||
|
}
|
||||||
|
period = actualPeriod();
|
||||||
|
if (accountPeriod(_from) != period) {
|
||||||
|
saveAccountPeriod(_from, period);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user