Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-agarwal-coinbase committed Oct 1, 2024
1 parent 2890e41 commit 80c4e01
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cdp/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def raw(self) -> DynamicFeeTransaction:
"type": "0x2", # EIP-1559 transaction type
}

# Handle the 'to' field separately
# Handle 'to' field separately since smart contract deployments have an empty 'to' field
if parsed_payload["to"]:
transaction_dict["to"] = Web3.to_bytes(hexstr=parsed_payload["to"])
else:
Expand Down
1 change: 0 additions & 1 deletion tests/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ def test_wallet_deploy_token_no_default_address(wallet_factory):
wallet.deploy_token(name="TestToken", symbol="TT", total_supply="1000000")


# Add similar tests for deploy_nft and deploy_multi_token with no default address
@patch("cdp.Cdp.use_server_signer", True)
def test_wallet_deploy_nft_no_default_address(wallet_factory):
"""Test the deploy_nft method of a Wallet with no default address."""
Expand Down
102 changes: 102 additions & 0 deletions tests/test_wallet_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,105 @@ def test_wallet_address_deploy_multi_token_with_server_signer(mock_api_clients,
# Verify that sign and broadcast methods are not called when using server signer
mock_smart_contract.sign.assert_not_called()
mock_smart_contract.broadcast.assert_not_called()


@patch("cdp.wallet_address.SmartContract")
@patch("cdp.Cdp.api_clients")
@patch("cdp.Cdp.use_server_signer", False)
def test_deploy_token_api_error(mock_api_clients, mock_smart_contract, wallet_address_with_key):
"""Test the deploy_token method raises an error when the create API call fails."""
mock_smart_contract.create.side_effect = Exception("API Error")

with pytest.raises(Exception, match="API Error"):
wallet_address_with_key.deploy_token(name="TestToken", symbol="TT", total_supply="1000000")

mock_smart_contract.create.assert_called_once()


@patch("cdp.wallet_address.SmartContract")
@patch("cdp.Cdp.api_clients")
@patch("cdp.Cdp.use_server_signer", False)
def test_deploy_token_broadcast_api_error(
mock_api_clients, mock_smart_contract, wallet_address_with_key
):
"""Test the deploy_token method raises an error when the broadcast API call fails."""
mock_smart_contract_instance = Mock(spec=SmartContract)
mock_smart_contract.create.return_value = mock_smart_contract_instance
mock_smart_contract_instance.broadcast.side_effect = Exception("API Error")

with pytest.raises(Exception, match="API Error"):
wallet_address_with_key.deploy_token(name="TestToken", symbol="TT", total_supply="1000000")

mock_smart_contract.create.assert_called_once()
mock_smart_contract_instance.sign.assert_called_once_with(wallet_address_with_key.key)
mock_smart_contract_instance.broadcast.assert_called_once()


@patch("cdp.wallet_address.SmartContract")
@patch("cdp.Cdp.api_clients")
@patch("cdp.Cdp.use_server_signer", False)
def test_deploy_nft_api_error(mock_api_clients, mock_smart_contract, wallet_address_with_key):
"""Test the deploy_nft method raises an error when the create API call fails."""
mock_smart_contract.create.side_effect = Exception("API Error")

with pytest.raises(Exception, match="API Error"):
wallet_address_with_key.deploy_nft(
name="TestNFT", symbol="TNFT", base_uri="https://example.com/nft/"
)

mock_smart_contract.create.assert_called_once()


@patch("cdp.wallet_address.SmartContract")
@patch("cdp.Cdp.api_clients")
@patch("cdp.Cdp.use_server_signer", False)
def test_deploy_nft_broadcast_api_error(
mock_api_clients, mock_smart_contract, wallet_address_with_key
):
"""Test the deploy_nft method raises an error when the broadcast API call fails."""
mock_smart_contract_instance = Mock(spec=SmartContract)
mock_smart_contract.create.return_value = mock_smart_contract_instance
mock_smart_contract_instance.broadcast.side_effect = Exception("API Error")

with pytest.raises(Exception, match="API Error"):
wallet_address_with_key.deploy_nft(
name="TestNFT", symbol="TNFT", base_uri="https://example.com/nft/"
)

mock_smart_contract.create.assert_called_once()
mock_smart_contract_instance.sign.assert_called_once_with(wallet_address_with_key.key)
mock_smart_contract_instance.broadcast.assert_called_once()


@patch("cdp.wallet_address.SmartContract")
@patch("cdp.Cdp.api_clients")
@patch("cdp.Cdp.use_server_signer", False)
def test_deploy_multi_token_api_error(
mock_api_clients, mock_smart_contract, wallet_address_with_key
):
"""Test the deploy_multi_token method raises an error when the create API call fails."""
mock_smart_contract.create.side_effect = Exception("API Error")

with pytest.raises(Exception, match="API Error"):
wallet_address_with_key.deploy_multi_token(uri="https://example.com/multi-token/{id}.json")

mock_smart_contract.create.assert_called_once()


@patch("cdp.wallet_address.SmartContract")
@patch("cdp.Cdp.api_clients")
@patch("cdp.Cdp.use_server_signer", False)
def test_deploy_multi_token_broadcast_api_error(
mock_api_clients, mock_smart_contract, wallet_address_with_key
):
"""Test the deploy_multi_token method raises an error when the broadcast API call fails."""
mock_smart_contract_instance = Mock(spec=SmartContract)
mock_smart_contract.create.return_value = mock_smart_contract_instance
mock_smart_contract_instance.broadcast.side_effect = Exception("API Error")

with pytest.raises(Exception, match="API Error"):
wallet_address_with_key.deploy_multi_token(uri="https://example.com/multi-token/{id}.json")

mock_smart_contract.create.assert_called_once()
mock_smart_contract_instance.sign.assert_called_once_with(wallet_address_with_key.key)
mock_smart_contract_instance.broadcast.assert_called_once()

0 comments on commit 80c4e01

Please sign in to comment.