-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(review): rewrite the code, with the suggestions from the review…
… and redo the test and add it to the integrations folder
- Loading branch information
1 parent
c7aea18
commit fab7d43
Showing
5 changed files
with
128 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
from unittest.mock import patch, MagicMock | ||
import boa | ||
|
||
def test_contract_verification(): | ||
""" | ||
Tests the smart contract verification process. It simulates both successful and failed verification scenarios | ||
using mocked API responses from Blockscout. | ||
""" | ||
code = """ | ||
@external | ||
def hello() -> String[32]: | ||
return "Hello, World!" | ||
""" | ||
|
||
mock_response = MagicMock() | ||
mock_response.json.return_value = {"status": "1"} | ||
mock_response.status_code = 200 | ||
|
||
with patch('requests.post', return_value=mock_response), \ | ||
patch.dict('os.environ', {'BLOCKSCOUT_API_KEY': '...'}): | ||
contract = boa.loads(code, explorer="blockscout") | ||
|
||
assert isinstance(contract, boa.contracts.vyper.vyper_contract.VyperContract), "Contract deployment failed or returned an incorrect type" | ||
assert contract.hello() == "Hello, World!", "Contract function 'hello()' returned an unexpected result" | ||
|
||
# Simulate a failed verification response | ||
mock_response.json.return_value = {"status": "0", "message": "Verification failed"} | ||
mock_response.status_code = 400 | ||
with patch('requests.post', return_value=mock_response), \ | ||
patch.dict('os.environ', {'BLOCKSCOUT_API_KEY': '...'}): | ||
contract = boa.loads(code, explorer="blockscout") | ||
# Add appropriate checks for failed verification | ||
|
||
# Test missing API key scenario | ||
with patch.dict('os.environ', {}, clear=True): | ||
contract = boa.loads(code, explorer="blockscout") |
Oops, something went wrong.