Esempio n. 1
0
def test_ERC20(alice_wallet, alice_address, bob_wallet, bob_address):
    #use DTFactory to create the token, and Datatoken to mint it
    f = dtfactory.DTFactory()
    dt_address = f.createToken('',
                               'TOK',
                               'TOK',
                               web3util.toBase18(100.0),
                               from_wallet=alice_wallet)
    dt = datatoken.Datatoken(dt_address)
    dt.mint(alice_address, web3util.toBase18(100.0), from_wallet=alice_wallet)

    #now that we've created & minted the token, we can use it with BToken interface
    token = btoken.BToken(dt_address)
    assert token.address == dt_address
    assert token.decimals() == 18
    assert token.balanceOf_base(alice_address) == web3util.toBase18(100.0)
    assert token.balanceOf_base(bob_address) == 0

    assert token.allowance_base(alice_address, bob_address) == 0
    token.approve(bob_address, int(1e18), from_wallet=alice_wallet)
    assert token.allowance_base(alice_address, bob_address) == int(1e18)

    #alice sends all her tokens to Bob, then Bob sends it back
    alice_TOK = token.balanceOf_base(alice_address)
    bob_TOK = token.balanceOf_base(bob_address)
    token.transfer(bob_address, alice_TOK, from_wallet=alice_wallet)
    assert token.balanceOf_base(alice_address) == 0
    assert token.balanceOf_base(bob_address) == (alice_TOK + bob_TOK)

    token.transfer(alice_address, alice_TOK, from_wallet=bob_wallet)
    assert token.balanceOf_base(alice_address) == alice_TOK
    assert token.balanceOf_base(bob_address) == bob_TOK
Esempio n. 2
0
 def _createDatatoken(self,dt_name:str,mint_amt:float)-> datatoken.Datatoken:
     """Create datatoken contract and mint DTs to self."""
     wallet = self._wallet._web3wallet
     DT_address = dtfactory.DTFactory().createToken(
         '', dt_name, dt_name, toBase18(mint_amt), from_wallet=wallet)
     DT = datatoken.Datatoken(DT_address)
     DT.mint(wallet.address, toBase18(mint_amt), from_wallet=wallet)
     return DT
Esempio n. 3
0
def _createDT(web3_w: web3wallet.Web3Wallet):
    DT_address = dtfactory.DTFactory().createToken('foo',
                                                   'DT1',
                                                   'DT1',
                                                   toBase18(_DT_INIT),
                                                   from_wallet=web3_w)
    DT = datatoken.Datatoken(DT_address)
    DT.mint(web3_w.address, toBase18(_DT_INIT), from_wallet=web3_w)
    return DT
Esempio n. 4
0
    def __init__(self, symbol: str):
        #A random wallet won't have ETH for gas fees. So, use
        # 'TEST_PRIVATE_KEY1' which got funds in ganache startup (see deploy.py)
        network = web3util.get_network()
        key1 = web3util.confFileValue(network, 'TEST_PRIVATE_KEY1')
        self._web3_wallet = web3wallet.Web3Wallet(key1)

        factory = dtfactory.DTFactory()
        token_address = factory.createToken('', symbol, symbol,
                                            constants.HUGEINT,
                                            self._web3_wallet)
        self._token = datatoken.Datatoken(token_address)
Esempio n. 5
0
def _deployAndMintToken(symbol: str, to_address: str) -> datatoken.Datatoken:
    network = web3util.get_network()
    private_key = web3util.confFileValue(network, 'TEST_PRIVATE_KEY1')
    from_wallet = Web3Wallet(private_key=private_key)
    factory = dtfactory.DTFactory()
    amount_base = web3util.toBase18(1000.0)
    dt_address = factory.createToken('', symbol, symbol, amount_base,
                                     from_wallet)
    dt = datatoken.Datatoken(dt_address)
    dt.mint(account=to_address,
            value_base=amount_base,
            from_wallet=from_wallet)

    return dt
Esempio n. 6
0
def test_ERC20(alice_wallet, alice_address,
               bob_wallet, bob_address):
    f = dtfactory.DTFactory()
    dt_address = f.createToken('foo', 'DT1', 'DT1', web3util.toBase18(100.0),
                               from_wallet=alice_wallet)
    dt = datatoken.Datatoken(dt_address)
    dt.mint(alice_address, web3util.toBase18(100.0), from_wallet=alice_wallet)

    #functionality inherited from btoken
    assert dt.address == dt_address
    assert dt.symbol() == 'DT1'
    assert dt.decimals() == 18
    assert dt.balanceOf_base(alice_address) == web3util.toBase18(100.0)
    dt.transfer(bob_address, web3util.toBase18(50.0), from_wallet=alice_wallet)
    assert dt.allowance_base(alice_address, bob_address) == 0
    dt.approve(bob_address, int(1e18), from_wallet=alice_wallet)
    assert dt.allowance_base(alice_address, bob_address) == int(1e18)
    
    #functionality for just datatoken
    assert dt.blob() == 'foo'
    assert 'mint' in dir(dt)
    assert 'setMinter' in dir(dt)
Esempio n. 7
0
def test1(alice_wallet):
    f = dtfactory.DTFactory()
    dt_address = f.createToken('foo', 'DT', 'DT', 100000, alice_wallet)
    dt = datatoken.Datatoken(dt_address)
    assert isinstance(dt, datatoken.Datatoken)
    assert dt.blob() == 'foo'