ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
5.02k stars 1.71k forks source link

Web3.py didn't throw error(in Remix it did) #1792

Closed Kindhearted57 closed 4 years ago

Kindhearted57 commented 4 years ago
apturl==0.5.2
asn1crypto==0.24.0
attrdict==2.0.1
attrs==19.3.0
base58==2.0.0
beautifulsoup4==4.8.0
bitarray==1.2.1
blake2b-py==0.1.3
Brlapi==0.6.6
bs4==0.0.1
cached-property==1.5.1
certifi==2020.4.5.1
cffi==1.14.0
chardet==3.0.4
coincurve==13.0.0
coloredlogs==14.0
command-not-found==0.3
configparser==5.0.0
coverage==5.1
cryptography==2.1.4
cupshelpers==1.0
cycler==0.10.0
cytoolz==0.10.1
defer==1.0.6
dictionaries==0.0.2
distro-info===0.18ubuntu0.18.04.1
eth-abi==2.1.1
eth-account==0.5.2
eth-bloom==1.0.3
eth-hash==0.2.0
eth-keyfile==0.5.1
eth-keys==0.3.3
eth-rlp==0.1.2
eth-tester==0.1.0b32
eth-typing==2.2.1
eth-utils==1.8.4
ethereum==2.3.2
ethereum-input-decoder==0.2.2
evdev==1.3.0
future==0.18.2
hexbytes==0.2.0
httplib2==0.9.2
humanfriendly==8.1
idna==2.9
importlib-metadata==1.6.0
inflection==0.3.1
ipfshttpclient==0.4.13.2
Jinja2==2.11.2
jsonschema==3.2.0
keyring==10.6.0
keyrings.alt==3.0
kiwisolver==1.2.0
language-selector==0.1
launchpadlib==1.10.6
lazr.restfulclient==0.13.5
lazr.uri==1.0.3
louis==3.5.0
lru-dict==1.1.6
lxml==4.4.1
macaroonbakery==1.1.3
Mako==1.0.7
MarkupSafe==1.0
matplotlib==3.2.1
mock==4.0.2
multiaddr==0.0.9
mypy-extensions==0.4.3
mythril==0.22.4
mythx-models==1.7.4
netaddr==0.7.19
netifaces==0.10.4
numpy==1.18.2
oauth==1.0.1
olefile==0.45.1
parsimonious==0.8.1
pbkdf2==1.3
persistent==4.6.4
pexpect==4.2.1
Pillow==5.1.0
plyvel==1.2.0
protobuf==3.11.3
py-ecc==1.6.0
py-evm==0.3.0a13
py-flags==1.1.4
py-solc==3.2.0
py-solc-x==0.6.0
pyasn1==0.4.8
pycairo==1.16.2
pycparser==2.20
pycrypto==2.6.1
pycryptodome==3.9.7
pycups==1.9.73
pyethash==0.1.27
pygobject==3.26.1
PyJWT==1.7.1
pymacaroons==0.13.0
PyNaCl==1.1.2
pyparsing==2.4.7
pyRFC3339==1.0
pyrsistent==0.16.0
pysha3==1.0.2
python-apt==1.6.5+ubuntu0.2
python-dateutil==2.8.1
python-debian==0.1.32
pythx==1.5.5
pytz==2018.3
pyxdg==0.25
PyYAML==3.12
reportlab==3.4.0
repoze.lru==0.7
requests==2.23.0
requests-unixsocket==0.1.5
rlp==1.2.0
scrypt==0.8.13
SecretStorage==2.3.1
semantic-version==2.8.4
simplejson==3.13.2
six==1.14.0
soupsieve==1.9.3
system-service==0.3
systemd-python==234
toolz==0.10.0
tqdm==4.46.0
transaction==3.0.0
trie==1.4.0
typing-extensions==3.7.4.2
ubuntu-drivers-common==0.0.0
ufw==0.36
unattended-upgrades==0.1
urllib3==1.25.9
usb-creator==0.3.3
varint==1.0.2
virtualenv==15.1.0
wadllib==1.3.2
web3==5.9.0
websockets==8.1
xkit==0.0.0
z3-solver==4.8.7.0
zipp==3.1.0
zope.interface==4.3.2

What was wrong?

The contracts I used:

EtherDelta(DEX)

Freedomcoin(Token)

Here is my logic:

I use userA who deployed the two contracts to transfer 100Ether to userB, then userB invoke depositToken, however, as there is no transferFrom in the token's contract, it will go to fallback function:

  function() {
    throw;
  }

clearly it will throw, and that's exactly what happened in remix.

However, when I tested this in bytecode using web3py, the transaction was successful, status was 1, and when I checked balanceOf in EtherDelta, it returned the true value. I don't know what's wrong. Is this something about web3py itself?

Here is my testing code, I used ganache-cli as testnet.

import json
from tqdm import trange
from web3 import Web3, HTTPProvider, IPCProvider, WebsocketProvider

account1 = "0x827A309CCf3a92F259E2081240Da9A503495F101"
account2 = "0x52EDd47566812fb01BdAA58d58630fe95C757CdD"

w3 = Web3(HTTPProvider('http://127.0.0.1:8545',request_kwargs={'timeout':600}))

DexBinCode =""
#I'm omitting this as it's too long, but I'm sure that the deployment is successful.

dexDeploymentReceipt = w3.eth.sendTransaction({'from':account1,'value':0,'data':DexBinCode,'gas':100000000})
dexDeployHash = Web3.toHex(dexDeploymentReceipt)
truedexDeploymentReceipt = w3.eth.getTransactionReceipt(dexDeployHash)
dex_address = truedexDeploymentReceipt['contractAddress']

TokenBinCode = ""
# Same as the DEX contract

# Deploy token contract
try:
    tokenDeploymentReceipt = w3.eth.sendTransaction({'from':account1,'value':0,'data':TokenBinCode,'gas':100000000})
    tokenDeployHash = Web3.toHex(tokenDeploymentReceipt)
    truetokenDeploymentReceipt = w3.eth.getTransactionReceipt(tokenDeployHash)
    token_address = truetokenDeploymentReceipt['contractAddress'] 

except:
    print('error1')

# Transfer 100 Ether from account1 to account2
try:
    setupBinCode = "0xa9059cbb000000000000000000000000"+account2.replace('0x','')+"0000000000000000000000000000000000000000000000000000000000000064"
    setupTransferReceipt = w3.eth.sendTransaction({'from':account1,'to':token_address,'value':0,'data':setupBinCode,'gas':100000000})
    setupTransferHash = Web3.toHex(setupTransferReceipt)
    truesetupTransferReceipt = w3.eth.getTransactionReceipt(setupTransferHash)
except:
    print('error2')

# depositToken with account2
try:
    depositBinCode = "0x338b5dea000000000000000000000000"+token_address.replace('0x','')+"00000000000000000000000000000000000000000000000000000000000001f4"
    balanceBinCode = "0xf7888aec000000000000000000000000"+token_address.replace('0x','')+"000000000000000000000000"+account2.replace('0x','')
    depositReceipt = w3.eth.sendTransaction({'from':account2,'to':dex_address,'value':0,'data':depositBinCode,'gas':1000000000})
    depositHash = Web3.toHex(depositReceipt)
    trueDepositReceipt = w3.eth.getTransactionReceipt(depositHash)
    print(trueDepositReceipt)
    balance = w3.eth.call({'from':account2,'to':dex_address,'data':balanceBinCode})
    balance = Web3.toHex(balance)
    print(balance)
    if balance !='0x00000000000000000000000000000000000000000000000000000000000001f4':
        print('error6')
except:
    print('error7')       

The result of trueDepositReceipt:

AttributeDict({'transactionHash': HexBytes('0xeb4e17dc0025e2edb8c2108944b3d521b71c0d527acd97f1c2fbfddb331bd76f'), 'transactionIndex': 0, 'blockHash': HexBytes('0xc71c82f0d38fa2c8ac6dfce57068dd93b1420d23e4b6a99ecbe5d269d56298b6'), 'blockNumber': 80, 'from': '0x52EDd47566812fb01BdAA58d58630fe95C757CdD', 'to': '0x552044ff5ca9F9094754C1ed53fD84Ac182eCC9B', 'gasUsed': 50181, 'cumulativeGasUsed': 50181, 'contractAddress': None, 'logs': [AttributeDict({'logIndex': 0, 'transactionIndex': 0, 'transactionHash': HexBytes('0xeb4e17dc0025e2edb8c2108944b3d521b71c0d527acd97f1c2fbfddb331bd76f'), 'blockHash': HexBytes('0xc71c82f0d38fa2c8ac6dfce57068dd93b1420d23e4b6a99ecbe5d269d56298b6'), 'blockNumber': 80, 'address': '0x552044ff5ca9F9094754C1ed53fD84Ac182eCC9B', 'data': '0x00000000000000000000000080eff541e03059f920931ab7d93c942e2da3052700000000000000000000000052edd47566812fb01bdaa58d58630fe95c757cdd00000000000000000000000000000000000000000000000000000000000001f400000000000000000000000000000000000000000000000000000000000001f4', 'topics': [HexBytes('0xdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7')], 'type': 'mined'})], 'status': 1, 'logsBloom': HexBytes('0x00002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000002000000000000000000000000000000000')})

Please don't ask why I'm using bytecode... That's the request for my experiment. I can make sure that there are nothing wrong with the function signatures.

Kindhearted57 commented 4 years ago

Ok so I got an reasonable answer from https://ethereum.stackexchange.com/questions/90150/what-is-the-gas-limit-for-a-fallback-function-called-when-the-method-does-not-ex/90159#90159, this shouldn't be something related to web3.py but solc. I'm closing this.