Solidity

鑄造測試失敗 - 失敗。原因:WRONG_FROM

  • August 20, 2022

很長一段時間以來,我一直試圖讓這個測試正常工作,在 8 個測試中,這是唯一一個失敗的測試,即使使用更詳細的測試提示 (-vvvv),我也無法理解出了什麼問題

測試程式碼:

function testCanBuyListing() public {
       uint256 userBalance = address(this).balance;
       nft.transferFrom(address(this), user, nftId);

       uint256 listingId = opensea.list(nft, nftId, 1 ether);

       vm.prank(user);
       opensea.buyListing{value: 1 ether}(listingId);
   }

錯誤(連同痕跡)

[141591] OpenseaTest::testCanBuyListing() 
   ├─ [32624] TestNFT::transferFrom(OpenseaTest: [0xb4c79dab8f259c7aee6e5b2aa729821864227e84], 0x0000000000000000000000000000000000000001, 1) 
   │   ├─ emit Transfer(from: OpenseaTest: [0xb4c79dab8f259c7aee6e5b2aa729821864227e84], to: 0x0000000000000000000000000000000000000001, id: 1)
   │   └─ ← ()
   ├─ [94435] Opensea::list(TestNFT: [0x185a4dc360ce69bdccee33b3784b0282f7961aea], 1, 1000000000000000000) 
   │   ├─ emit NewListing(listing: (0x185a4dc360ce69bdccee33b3784b0282f7961aea, 1, 0xb4c79dab8f259c7aee6e5b2aa729821864227e84, 1000000000000000000))
   │   ├─ [842] TestNFT::transferFrom(OpenseaTest: [0xb4c79dab8f259c7aee6e5b2aa729821864227e84], Opensea: [0xce71065d4017f316ec606fe4422e11eb2c47c246], 1) 
   │   │   └─ ← "WRONG_FROM"
   │   └─ ← "WRONG_FROM"
   └─ ← "WRONG_FROM"

錯誤可能來自任何一個address(this)並且user是相同的地址或address(this)可能沒有 nft

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