Skip to content

Commit

Permalink
Feat/chain simulator faucet (#86)
Browse files Browse the repository at this point in the history
* feat: add ChainSimulatorFaucetStep

* docs: show how to use ChainSimulatorFaucetStep

* docs: changelog

* Bump version: 3.0.0-dev9 → 3.0.0-dev10

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
EtienneWallet and github-actions[bot] authored Dec 9, 2024
1 parent 4f8fced commit fa1f51e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 21 deletions.
1 change: 1 addition & 0 deletions docs/source/dev_documentation/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- `SetVarsStep`
- `GenerateWalletsStep`
- `R3D4FaucetStep`
- `ChainSimulatorFaucetStep`


### Changed
Expand Down
16 changes: 15 additions & 1 deletion docs/source/user_documentation/steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -802,4 +802,18 @@ targets:
- erd1y3296u7m2v5653pddey3p7l5zacqmsgqc7vsu3w74p9jm2qp3tqqz950yl # or direct bech32
```

For each address, the maximum amount of EGLD (1 EGLD as of December 2024) will be requested.
For each address, the maximum amount of EGLD (1 EGLD as of December 2024) will be requested.


(chain_simulator_faucet_target)=
### Chain Simulator Faucet Step

This `Step` allows you to request EGLD on the chain-simulator.

```yaml
type: ChainSimulatorFaucet
amount: 1000000000000000000 # 1.0 EGLD
targets:
- alice # account name handeld by MxOps
- erd1y3296u7m2v5653pddey3p7l5zacqmsgqc7vsu3w74p9jm2qp3tqqz950yl # or direct bech32
```
74 changes: 56 additions & 18 deletions mxops/execution/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __post_init__(self):
if len(self.checks) > 0 and isinstance(self.checks[0], Dict):
self.checks = instanciate_checks(self.checks)

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Interface for the method that will build transaction to send. This transaction
is meant to contain all the data specific to this Step.
Expand Down Expand Up @@ -143,7 +143,7 @@ def execute(self):
Execute the workflow for a transaction Step: build, send, check
and post execute
"""
tx = self._build_unsigned_transaction()
tx = self.build_unsigned_transaction()
self.sign_transaction(tx)

if len(self.checks) > 0:
Expand Down Expand Up @@ -223,7 +223,7 @@ class ContractDeployStep(TransactionStep):
payable_by_sc: bool = False
arguments: List = field(default_factory=list)

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction for a contract deployment
Expand Down Expand Up @@ -320,7 +320,7 @@ class ContractUpgradeStep(TransactionStep):
arguments: List = field(default_factory=lambda: [])
abi_path: Optional[str] = None

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction for a contract upgrade
Expand Down Expand Up @@ -399,7 +399,7 @@ class ContractCallStep(TransactionStep):
value: int | str = 0
esdt_transfers: List[EsdtTransfer] = field(default_factory=lambda: [])

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction for a contract call
Expand Down Expand Up @@ -906,7 +906,7 @@ class FungibleIssueStep(TransactionStep):
can_upgrade: bool = False
can_add_special_roles: bool = False

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction to issue a fungible token
Expand Down Expand Up @@ -979,7 +979,7 @@ class NonFungibleIssueStep(TransactionStep):
can_add_special_roles: bool = False
can_transfer_nft_create_role: bool = False

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction to issue a non fungible token
Expand Down Expand Up @@ -1045,7 +1045,7 @@ class SemiFungibleIssueStep(TransactionStep):
can_add_special_roles: bool = False
can_transfer_nft_create_role: bool = False

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction to issue a semi fungible token
Expand Down Expand Up @@ -1112,7 +1112,7 @@ class MetaIssueStep(TransactionStep):
can_add_special_roles: bool = False
can_transfer_nft_create_role: bool = False

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction to issue a meta token
Expand Down Expand Up @@ -1197,7 +1197,7 @@ class ManageFungibleTokenRolesStep(ManageTokenRolesStep):
"ESDTTransferRole",
}

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction to set roles on a fungible token
Expand Down Expand Up @@ -1250,7 +1250,7 @@ class ManageNonFungibleTokenRolesStep(ManageTokenRolesStep):
"ESDTTransferRole",
}

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction to set roles on a non fungible token
Expand Down Expand Up @@ -1306,7 +1306,7 @@ class ManageSemiFungibleTokenRolesStep(ManageTokenRolesStep):
"ESDTTransferRole",
}

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction to set roles on a non fungible token
Expand Down Expand Up @@ -1362,7 +1362,7 @@ class FungibleMintStep(TransactionStep):
token_identifier: str
amount: Union[str, int]

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction to mint a fungible token
Expand Down Expand Up @@ -1398,7 +1398,7 @@ class NonFungibleMintStep(TransactionStep):
attributes: str = ""
uris: List[str] = field(default_factory=lambda: [])

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction to mint a fungible token
Expand Down Expand Up @@ -1450,7 +1450,7 @@ class EgldTransferStep(TransactionStep):
receiver: str
amount: Union[str, int]

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction for an egld transfer
Expand Down Expand Up @@ -1484,7 +1484,7 @@ class FungibleTransferStep(TransactionStep):
token_identifier: str
amount: Union[str, int]

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction for an ESDT transfer
Expand Down Expand Up @@ -1522,7 +1522,7 @@ class NonFungibleTransferStep(TransactionStep):
nonce: Union[str, int]
amount: Union[str, int]

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction for a non fungible transfer
Expand Down Expand Up @@ -1578,7 +1578,7 @@ def __post_init__(self):
raise ValueError(f"Unexpected type: {type(trf)}")
self.transfers = checked_transfers

def _build_unsigned_transaction(self) -> Transaction:
def build_unsigned_transaction(self) -> Transaction:
"""
Build the transaction for multiple transfers
Expand Down Expand Up @@ -1849,3 +1849,41 @@ def request_faucet(self, bech32: str, token_id: str, amount: str):
if "error" in return_data:
raise errors.FaucetFailed(return_data["error"])
LOGGER.info(f"Response from faucet: {return_data['success']}")


@dataclass
class ChainSimulatorFaucetStep(Step):
"""
Represents a step to request some EGLD from the chain-simulator faucet
(aka initial wallets of the chain simulator)
"""

targets: List[str]
amount: int
ALLOWED_NETWORKS: ClassVar[Set] = (NetworkEnum.CHAIN_SIMULATOR,)

def execute(self):
"""
Seach for the r3d4 token id of EGLD in the current network and
ask for EGLD from the faucet
"""
scenario_data = ScenarioData.get()
if scenario_data.network not in self.ALLOWED_NETWORKS:
raise errors.WrongNetworkForStep(
scenario_data.network, self.ALLOWED_NETWORKS
)
proxy = MyProxyNetworkProvider()
initial_wallet_data = proxy.get_initial_wallets()
sender = initial_wallet_data["balanceWallets"]["0"]["address"]["bech32"]
sender_nonce = proxy.get_account(Address.from_bech32(sender)).nonce
for target in self.targets:
egld_step = EgldTransferStep(
sender=sender, receiver=target, amount=self.amount
)
tx = egld_step.build_unsigned_transaction()
tx.signature = b"aa"
tx.nonce = sender_nonce
on_chain_tx = send_and_wait_for_result(tx)
SuccessCheck().raise_on_failure(on_chain_tx)
LOGGER.info(f"Transaction successful: {get_tx_link(on_chain_tx.hash)}")
sender_nonce += 1
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "mxops"
version = "3.0.0-dev9"
version = "3.0.0-dev10"
authors = [
{name="Etienne Wallet"},
]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.0.0-dev9
current_version = 3.0.0-dev10
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(-(?P<release>\w+)(?P<build>\d+))?
serialize =
{major}.{minor}.{patch}-{release}{build}
Expand Down

0 comments on commit fa1f51e

Please sign in to comment.