mirror of
https://github.com/chaintool-py/eth-erc20.git
synced 2024-11-21 17:26:47 +01:00
Add giftable token contract metadata
This commit is contained in:
parent
99e82dd3bf
commit
0937ecb8cd
@ -1,3 +1,5 @@
|
|||||||
|
* 0.6.2
|
||||||
|
- Add Giftable Token contract metadata
|
||||||
* 0.6.1
|
* 0.6.1
|
||||||
- Add explicit burn (reduces supply) to giftable token
|
- Add explicit burn (reduces supply) to giftable token
|
||||||
* 0.6.0
|
* 0.6.0
|
||||||
|
169
python/eth_erc20/unittest/base.py
Normal file
169
python/eth_erc20/unittest/base.py
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
# standard imports
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
from chainlib.eth.unittest.ethtester import EthTesterCase
|
||||||
|
from chainlib.eth.nonce import RPCNonceOracle
|
||||||
|
from chainlib.eth.gas import OverrideGasOracle
|
||||||
|
from chainlib.eth.tx import (
|
||||||
|
transaction,
|
||||||
|
receipt,
|
||||||
|
)
|
||||||
|
from hexathon import strip_0x
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from giftable_erc20_token.unittest import TestGiftableToken
|
||||||
|
from eth_erc20 import ERC20
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class TestInterface:
|
||||||
|
|
||||||
|
def test_balance(self):
|
||||||
|
c = ERC20(self.chain_spec)
|
||||||
|
o = c.balance_of(self.address, self.accounts[0], sender_address=self.accounts[0])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
balance = ERC20.parse_balance(r)
|
||||||
|
self.assertEqual(self.initial_supply, balance)
|
||||||
|
|
||||||
|
|
||||||
|
def test_supply(self):
|
||||||
|
c = ERC20(self.chain_spec)
|
||||||
|
o = c.total_supply(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
supply = ERC20.parse_total_supply(r)
|
||||||
|
self.assertEqual(self.initial_supply, supply)
|
||||||
|
|
||||||
|
|
||||||
|
def test_name(self):
|
||||||
|
c = ERC20(self.chain_spec)
|
||||||
|
o = c.name(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
name = ERC20.parse_name(r)
|
||||||
|
self.assertEqual(self.name, name)
|
||||||
|
|
||||||
|
|
||||||
|
def test_symbol(self):
|
||||||
|
c = ERC20(self.chain_spec)
|
||||||
|
o = c.symbol(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
symbol = ERC20.parse_symbol(r)
|
||||||
|
self.assertEqual(self.symbol, symbol)
|
||||||
|
|
||||||
|
|
||||||
|
def test_transfer(self):
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
|
||||||
|
gas_oracle = OverrideGasOracle(limit=100000, conn=self.conn)
|
||||||
|
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||||
|
(tx_hash, o) = c.transfer(self.address, self.accounts[0], self.accounts[1], 1000)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
o = c.balance_of(self.address, self.accounts[0], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
balance = c.parse_balance(r)
|
||||||
|
self.assertEqual(balance, self.initial_supply - 1000)
|
||||||
|
|
||||||
|
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
balance = c.parse_balance(r)
|
||||||
|
self.assertEqual(balance, 1000)
|
||||||
|
|
||||||
|
o = transaction(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
data = c.parse_transfer_request(r['data'])
|
||||||
|
self.assertEqual(data[0], strip_0x(self.accounts[1]))
|
||||||
|
self.assertEqual(data[1], 1000)
|
||||||
|
|
||||||
|
|
||||||
|
def test_transfer_from(self):
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
|
||||||
|
gas_oracle = OverrideGasOracle(limit=100000, conn=self.conn)
|
||||||
|
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||||
|
(tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 1000)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
o = c.allowance(self.address, self.accounts[0], self.accounts[1], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
allowance = c.parse_allowance(r)
|
||||||
|
self.assertEqual(allowance, 1000)
|
||||||
|
|
||||||
|
o = transaction(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
data = c.parse_approve_request(r['data'])
|
||||||
|
self.assertEqual(data[0], strip_0x(self.accounts[1]))
|
||||||
|
self.assertEqual(data[1], 1000)
|
||||||
|
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[1], conn=self.conn)
|
||||||
|
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||||
|
(tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[0], self.accounts[2], 1001)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 0)
|
||||||
|
|
||||||
|
o = transaction(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
data = c.parse_transfer_from_request(r['data'])
|
||||||
|
self.assertEqual(data[0], strip_0x(self.accounts[0]))
|
||||||
|
self.assertEqual(data[1], strip_0x(self.accounts[2]))
|
||||||
|
self.assertEqual(data[2], 1001)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[0], self.accounts[2], 1000)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
o = c.balance_of(self.address, self.accounts[0], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
balance = c.parse_balance(r)
|
||||||
|
self.assertEqual(balance, self.initial_supply - 1000)
|
||||||
|
|
||||||
|
o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
balance = c.parse_balance(r)
|
||||||
|
self.assertEqual(balance, 1000)
|
||||||
|
|
||||||
|
|
||||||
|
def test_revoke_approve(self):
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
|
||||||
|
gas_oracle = OverrideGasOracle(limit=100000, conn=self.conn)
|
||||||
|
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||||
|
(tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 1000)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 999)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 0)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 0)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
o = c.allowance(self.address, self.accounts[0], self.accounts[1], sender_address=self.accounts[0])
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
allowance = c.parse_allowance(r)
|
||||||
|
self.assertEqual(allowance, 0)
|
||||||
|
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[1], conn=self.conn)
|
||||||
|
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||||
|
(tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[0], self.accounts[2], 1)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.rpc.do(o)
|
||||||
|
self.assertEqual(r['status'], 0)
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
python/giftable_erc20_token/data/StaticToken.bin
Normal file
1
python/giftable_erc20_token/data/StaticToken.bin
Normal file
File diff suppressed because one or more lines are too long
1
python/giftable_erc20_token/data/StaticToken.json
Normal file
1
python/giftable_erc20_token/data/StaticToken.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"uint256","name":"_supply","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
@ -0,0 +1 @@
|
|||||||
|
{"compiler":{"version":"0.8.18+commit.87f61d96"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"uint256","name":"_supply","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"StaticToken.sol":"StaticToken"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"StaticToken.sol":{"keccak256":"0x7afcc41cbaaaeeac2e372c50ed4cf6962035af89e33b500a65927f46d8bf31f2","license":"GPL-3.0-or-later","urls":["bzz-raw://4077171f628fd470cb7f72ca80426297132050f4d08380b55ca74c87e3df2727","dweb:/ipfs/QmWvgFNWrRtzQFejyfjy6LaerghSnYQ86R5WVTnXS7wiuD"]}},"version":1}
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = eth-erc20
|
name = eth-erc20
|
||||||
version = 0.6.1
|
version = 0.6.2
|
||||||
description = ERC20 interface and simple contract with deployment script that lets any address mint and gift itself tokens.
|
description = ERC20 interface and simple contract with deployment script that lets any address mint and gift itself tokens.
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
@ -1,176 +1,13 @@
|
|||||||
# standard imports
|
# import logging
|
||||||
import logging
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
# external imports
|
|
||||||
from chainlib.eth.unittest.ethtester import EthTesterCase
|
|
||||||
from chainlib.connection import RPCConnection
|
|
||||||
from chainlib.eth.nonce import RPCNonceOracle
|
|
||||||
from chainlib.eth.gas import OverrideGasOracle
|
|
||||||
from chainlib.eth.tx import (
|
|
||||||
transaction,
|
|
||||||
receipt,
|
|
||||||
)
|
|
||||||
from chainlib.eth.address import to_checksum_address
|
|
||||||
from hexathon import strip_0x
|
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from giftable_erc20_token.unittest import TestGiftableToken
|
from giftable_erc20_token.unittest import TestGiftableToken
|
||||||
from eth_erc20 import ERC20
|
from eth_erc20.unittest import TestInterface
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
|
||||||
logg = logging.getLogger()
|
|
||||||
|
|
||||||
|
|
||||||
class TestToken(TestGiftableToken):
|
class TestBasic(TestGiftableToken, TestInterface):
|
||||||
|
pass
|
||||||
def test_balance(self):
|
|
||||||
c = ERC20(self.chain_spec)
|
|
||||||
o = c.balance_of(self.address, self.accounts[0], sender_address=self.accounts[0])
|
|
||||||
r = self.conn.do(o)
|
|
||||||
balance = ERC20.parse_balance(r)
|
|
||||||
self.assertEqual(self.initial_supply, balance)
|
|
||||||
|
|
||||||
|
|
||||||
def test_supply(self):
|
|
||||||
c = ERC20(self.chain_spec)
|
|
||||||
o = c.total_supply(self.address, sender_address=self.accounts[0])
|
|
||||||
r = self.conn.do(o)
|
|
||||||
supply = ERC20.parse_total_supply(r)
|
|
||||||
self.assertEqual(self.initial_supply, supply)
|
|
||||||
|
|
||||||
|
|
||||||
def test_name(self):
|
|
||||||
c = ERC20(self.chain_spec)
|
|
||||||
o = c.name(self.address, sender_address=self.accounts[0])
|
|
||||||
r = self.conn.do(o)
|
|
||||||
name = ERC20.parse_name(r)
|
|
||||||
self.assertEqual(self.name, name)
|
|
||||||
|
|
||||||
|
|
||||||
def test_symbol(self):
|
|
||||||
c = ERC20(self.chain_spec)
|
|
||||||
o = c.symbol(self.address, sender_address=self.accounts[0])
|
|
||||||
r = self.conn.do(o)
|
|
||||||
symbol = ERC20.parse_symbol(r)
|
|
||||||
self.assertEqual(self.symbol, symbol)
|
|
||||||
|
|
||||||
|
|
||||||
def test_transfer(self):
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
|
|
||||||
gas_oracle = OverrideGasOracle(limit=100000, conn=self.conn)
|
|
||||||
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
|
||||||
(tx_hash, o) = c.transfer(self.address, self.accounts[0], self.accounts[1], 1000)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
o = receipt(tx_hash)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
self.assertEqual(r['status'], 1)
|
|
||||||
|
|
||||||
o = c.balance_of(self.address, self.accounts[0], sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
balance = c.parse_balance(r)
|
|
||||||
self.assertEqual(balance, self.initial_supply - 1000)
|
|
||||||
|
|
||||||
o = c.balance_of(self.address, self.accounts[1], sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
balance = c.parse_balance(r)
|
|
||||||
self.assertEqual(balance, 1000)
|
|
||||||
|
|
||||||
o = transaction(tx_hash)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
data = c.parse_transfer_request(r['data'])
|
|
||||||
self.assertEqual(data[0], strip_0x(self.accounts[1]))
|
|
||||||
self.assertEqual(data[1], 1000)
|
|
||||||
|
|
||||||
|
|
||||||
def test_transfer_from(self):
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
|
|
||||||
gas_oracle = OverrideGasOracle(limit=100000, conn=self.conn)
|
|
||||||
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
|
||||||
(tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 1000)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
o = receipt(tx_hash)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
self.assertEqual(r['status'], 1)
|
|
||||||
|
|
||||||
o = c.allowance(self.address, self.accounts[0], self.accounts[1], sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
allowance = c.parse_allowance(r)
|
|
||||||
self.assertEqual(allowance, 1000)
|
|
||||||
|
|
||||||
o = transaction(tx_hash)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
data = c.parse_approve_request(r['data'])
|
|
||||||
self.assertEqual(data[0], strip_0x(self.accounts[1]))
|
|
||||||
self.assertEqual(data[1], 1000)
|
|
||||||
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[1], conn=self.conn)
|
|
||||||
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
|
||||||
(tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[0], self.accounts[2], 1001)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
o = receipt(tx_hash)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
self.assertEqual(r['status'], 0)
|
|
||||||
|
|
||||||
o = transaction(tx_hash)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
data = c.parse_transfer_from_request(r['data'])
|
|
||||||
self.assertEqual(data[0], strip_0x(self.accounts[0]))
|
|
||||||
self.assertEqual(data[1], strip_0x(self.accounts[2]))
|
|
||||||
self.assertEqual(data[2], 1001)
|
|
||||||
|
|
||||||
(tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[0], self.accounts[2], 1000)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
o = receipt(tx_hash)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
self.assertEqual(r['status'], 1)
|
|
||||||
|
|
||||||
o = c.balance_of(self.address, self.accounts[0], sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
balance = c.parse_balance(r)
|
|
||||||
self.assertEqual(balance, self.initial_supply - 1000)
|
|
||||||
|
|
||||||
o = c.balance_of(self.address, self.accounts[2], sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
balance = c.parse_balance(r)
|
|
||||||
self.assertEqual(balance, 1000)
|
|
||||||
|
|
||||||
|
|
||||||
def test_revoke_approve(self):
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
|
|
||||||
gas_oracle = OverrideGasOracle(limit=100000, conn=self.conn)
|
|
||||||
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
|
||||||
(tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 1000)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
o = receipt(tx_hash)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
self.assertEqual(r['status'], 1)
|
|
||||||
|
|
||||||
(tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 999)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
o = receipt(tx_hash)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
self.assertEqual(r['status'], 0)
|
|
||||||
|
|
||||||
(tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 0)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
o = receipt(tx_hash)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
self.assertEqual(r['status'], 1)
|
|
||||||
|
|
||||||
o = c.allowance(self.address, self.accounts[0], self.accounts[1], sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
allowance = c.parse_allowance(r)
|
|
||||||
self.assertEqual(allowance, 0)
|
|
||||||
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[1], conn=self.conn)
|
|
||||||
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
|
||||||
(tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[0], self.accounts[2], 1)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
o = receipt(tx_hash)
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
self.assertEqual(r['status'], 0)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -52,7 +52,7 @@ contract GiftableToken {
|
|||||||
// Implements Burner
|
// Implements Burner
|
||||||
event Burn(uint256 _value);
|
event Burn(uint256 _value);
|
||||||
|
|
||||||
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _expireTimestamp) public {
|
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _expireTimestamp) {
|
||||||
owner = msg.sender;
|
owner = msg.sender;
|
||||||
name = _name;
|
name = _name;
|
||||||
symbol = _symbol;
|
symbol = _symbol;
|
||||||
@ -61,7 +61,7 @@ contract GiftableToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Implements ERC20
|
// Implements ERC20
|
||||||
function totalSupply() public returns (uint256) {
|
function totalSupply() public view returns (uint256) {
|
||||||
return totalMinted - burned;
|
return totalMinted - burned;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,6 +137,7 @@ contract GiftableToken {
|
|||||||
burned += _value;
|
burned += _value;
|
||||||
|
|
||||||
emit Burn(_value);
|
emit Burn(_value);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ERC20
|
// Implements ERC20
|
||||||
@ -166,10 +167,11 @@ contract GiftableToken {
|
|||||||
function transferOwnership(address _newOwner) public returns (bool) {
|
function transferOwnership(address _newOwner) public returns (bool) {
|
||||||
require(msg.sender == owner);
|
require(msg.sender == owner);
|
||||||
owner = _newOwner;
|
owner = _newOwner;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements EIP165
|
// Implements EIP165
|
||||||
function supportsInterface(bytes4 _sum) public returns (bool) {
|
function supportsInterface(bytes4 _sum) public pure returns (bool) {
|
||||||
if (_sum == 0xc6bb4b70) { // ERC20
|
if (_sum == 0xc6bb4b70) { // ERC20
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,15 @@ SOLC = /usr/bin/solc
|
|||||||
|
|
||||||
all:
|
all:
|
||||||
$(SOLC) --bin GiftableToken.sol --evm-version byzantium | awk 'NR>3' > GiftableToken.bin
|
$(SOLC) --bin GiftableToken.sol --evm-version byzantium | awk 'NR>3' > GiftableToken.bin
|
||||||
truncate -s -1 GiftableToken.bin
|
|
||||||
$(SOLC) --abi GiftableToken.sol --evm-version byzantium | awk 'NR>3' > GiftableToken.json
|
$(SOLC) --abi GiftableToken.sol --evm-version byzantium | awk 'NR>3' > GiftableToken.json
|
||||||
|
$(SOLC) --metadata GiftableToken.sol --evm-version byzantium | awk 'NR>3' > GiftableToken.metadata.json
|
||||||
$(SOLC) --bin StaticToken.sol --evm-version byzantium | awk 'NR>3' > StaticToken.bin
|
$(SOLC) --bin StaticToken.sol --evm-version byzantium | awk 'NR>3' > StaticToken.bin
|
||||||
truncate -s -1 StaticToken.bin
|
|
||||||
$(SOLC) --abi StaticToken.sol --evm-version byzantium | awk 'NR>3' > StaticToken.json
|
$(SOLC) --abi StaticToken.sol --evm-version byzantium | awk 'NR>3' > StaticToken.json
|
||||||
|
$(SOLC) --metadata StaticToken.sol --evm-version byzantium | awk 'NR>3' > StaticToken.metadata.json
|
||||||
|
truncate -s -1 StaticToken.bin
|
||||||
|
truncate -s -1 GiftableToken.bin
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
cp -v Giftable*{json,bin} ../python/giftable_erc20_token/data/
|
cp -v *.json ../python/giftable_erc20_token/data/
|
||||||
cp -v Static*{json,bin} ../python/static_token/data/
|
cp -v *.bin ../python/giftable_erc20_token/data/
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"uint256","name":"_supply","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"uint256","name":"_supply","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
||||||
|
@ -24,7 +24,7 @@ contract StaticToken {
|
|||||||
event TransferFrom(address indexed _from, address indexed _to, address indexed _spender, uint256 _value);
|
event TransferFrom(address indexed _from, address indexed _to, address indexed _spender, uint256 _value);
|
||||||
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
|
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
|
||||||
|
|
||||||
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _supply) public {
|
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _supply) {
|
||||||
owner = msg.sender;
|
owner = msg.sender;
|
||||||
name = _name;
|
name = _name;
|
||||||
symbol = _symbol;
|
symbol = _symbol;
|
||||||
@ -64,7 +64,7 @@ contract StaticToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Implements EIP165
|
// Implements EIP165
|
||||||
function supportsInterface(bytes4 _sum) public returns (bool) {
|
function supportsInterface(bytes4 _sum) public pure returns (bool) {
|
||||||
if (_sum == 0xc6bb4b70) { // ERC20
|
if (_sum == 0xc6bb4b70) { // ERC20
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user