Ether

布朗尼 python 測試在斷言階段失敗

  • November 27, 2021

我在 youtube 上的巧克力蛋糕項目課程之後執行了這個測試。

我執行了“test_issue_token”測試,它給了我這個錯誤:

=========================================== FAILURES ============================================
_______________________________________ test_issue_tokens _______________________________________

amount_staked = 1000000000000000000

   def test_issue_tokens(amount_staked):
       # arrange
       if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
           pytest.skip("Only for local tests")
       account = get_account()
       token_farm, dapp_token = test_stake_tokens(amount_staked)
       starting_balance = dapp_token.balanceOf(account.address)
       # act
       tx = token_farm.issueTokens({"from": account})
       tx.wait(1)
       # assert
       # 1 dapp token = è uguale a una singola unita del prezzo di 1 eth
       # se eth vale 2000$ allora 2000 dapp tokens = 1 eth
>       assert (
           dapp_token.balanceOf(account.address)
           == starting_balance + INITIAL_PRICE_FEED_VALUE
       )
E       AssertionError: assert 99000000000000000000 == (99000000000000000000 + 2000000000000000000000)
E        +  where 99000000000000000000 = <ContractCall 'balanceOf(address account)'>('0x66aB6D9362d4F35596279692F0251Db635165871')
E        +    where <ContractCall 'balanceOf(address account)'> = <DappToken Contract '0x3194cBDC3dbcd3E11a07892e7bA5c3394048Cc87'>.balanceOf
E        +    and   '0x66aB6D9362d4F35596279692F0251Db635165871' = <Account '0x66aB6D9362d4F35596279692F0251Db635165871'>.address

tests\unit\test_token_farm.py:62: AssertionError
------------------------------------- Captured stdout call -------------------------------------- 
Mocks deployed!
==================================== short test summary info ==================================== 
FAILED tests/unit/test_token_farm.py::test_issue_tokens - AssertionError: assert 99000000000000...=============================== 1 failed, 2 deselected in 10.22s ================================ 

似乎issueToken 函式畢竟沒有發出令牌,我通過複製粘貼 repo 程式碼來執行它以查看是否輸入錯誤,但事實並非如此

有人可以幫我嗎?

已解決:我忘記為在 issueToken 函式中使用的 getTotalUserValue 函式中的附加值返回返回語句

引用自:https://ethereum.stackexchange.com/questions/114334