Skip to content

Commit

Permalink
Add unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Aug 19, 2024
1 parent bd46ed3 commit f64dd9e
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[
{
"miniBlocks": [
{
"transactions": [
{
"type": "normal",
"processingTypeOnSource": "SCDeployment",
"processingTypeOnDestination": "SCDeployment",
"hash": "2459bb2b9a64c1c920777ecbdaf0fa33d7fe8bcd24d7164562f341b2e4f702da",
"value": "10000000000000000",
"receiver": "erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu",
"sender": "erd1tn62hjp72rznp8vq0lplva5csav6rccpqqdungpxtqz0g2hcq6uq9k4cc6",
"logs": {
"address": "erd1tn62hjp72rznp8vq0lplva5csav6rccpqqdungpxtqz0g2hcq6uq9k4cc6",
"events": [
{
"address": "erd1qqqqqqqqqqqqqpgqc4vdnqgc48ww26ljxqe2flgl86jewg0nq6uqna2ymj",
"identifier": "SCDeploy",
"topics": [
"AAAAAAAAAAAFAMVY2YEYqdzla/IwMqT9Hz6llyHzBrg=",
"XPSryD5QxTCdgH/D9naYh1mh4wEAG8mgJlgE9Cr4Brg=",
"v5gJ+IK1KdPGJfGYibrKij1SO0bzAAhfUVsODJ8midg="
],
"data": null,
"additionalData": null
},
{
"address": "erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu",
"identifier": "writeLog",
"topics": [
"XPSryD5QxTCdgH/D9naYh1mh4wEAG8mgJlgE9Cr4Brg=",
"QHRvbyBtdWNoIGdhcyBwcm92aWRlZCBmb3IgcHJvY2Vzc2luZzogZ2FzIHByb3ZpZGVkID0gNDU4ODUwMCwgZ2FzIHVzZWQgPSAzMzQ1MDU="
],
"data": "QDZmNmI=",
"additionalData": ["QDZmNmI="]
}
]
},
"status": "success",
"operation": "scDeploy",
"initiallyPaidFee": "457385000000000",
"chainID": "T",
"version": 2,
"options": 0
}
]
}
]
}
]
6 changes: 3 additions & 3 deletions server/services/transactionsTransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,11 @@ func (transformer *transactionsTransformer) addOperationsGivenTransactionEvents(
}

for _, event := range eventsSCDeploy {
// Handle deployments with transfer of value
// Handle direct deployments with transfer of value (indirect deployments are currently excluded to prevent any potential misinterpretations)..
if tx.Receiver == systemContractDeployAddress {
operations := []*types.Operation{
// Deployer's balance change is already captured in non-events-based operations.
// Let's simulate the transfer from the System deployment address to the contract address.
// Deployer's balance change is already captured in operations recovered not from logs / events, but from the transaction itself.
// It remains to "simulate" the transfer from the System deployment address to the contract address.
{
Type: opTransfer,
Account: addressToAccountIdentifier(tx.Receiver),
Expand Down
60 changes: 60 additions & 0 deletions server/services/transactionsTransformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,66 @@ func TestTransactionsTransformer_InvalidTxToRosettaTx(t *testing.T) {
require.Equal(t, expectedTx, rosettaTx)
}

func TestTransactionsTransformer_TransformBlockTxsHavingDirectSCDeployWithValue(t *testing.T) {
networkProvider := testscommon.NewNetworkProviderMock()
networkProvider.MockObservedActualShard = 0

extension := newNetworkProviderExtension(networkProvider)
transformer := newTransactionsTransformer(networkProvider)

blocks, err := readTestBlocks("testdata/blocks_with_direct_sc_deploy_with_value.json")
require.Nil(t, err)

txs, err := transformer.transformBlockTxs(blocks[0])
require.Nil(t, err)
require.Len(t, txs, 1)
require.Len(t, txs[0].Operations, 5)

expectedTx := &types.Transaction{
TransactionIdentifier: hashToTransactionIdentifier("2459bb2b9a64c1c920777ecbdaf0fa33d7fe8bcd24d7164562f341b2e4f702da"),
Operations: []*types.Operation{
{
Type: opTransfer,
OperationIdentifier: indexToOperationIdentifier(0),
Account: addressToAccountIdentifier("erd1tn62hjp72rznp8vq0lplva5csav6rccpqqdungpxtqz0g2hcq6uq9k4cc6"),
Amount: extension.valueToNativeAmount("-10000000000000000"),
Status: &opStatusSuccess,
},
{
Type: opTransfer,
OperationIdentifier: indexToOperationIdentifier(1),
Account: addressToAccountIdentifier("erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu"),
Amount: extension.valueToNativeAmount("10000000000000000"),
Status: &opStatusSuccess,
},
{
Type: opFee,
OperationIdentifier: indexToOperationIdentifier(2),
Account: addressToAccountIdentifier("erd1tn62hjp72rznp8vq0lplva5csav6rccpqqdungpxtqz0g2hcq6uq9k4cc6"),
Amount: extension.valueToNativeAmount("-457385000000000"),
Status: &opStatusSuccess,
},
{
Type: opTransfer,
OperationIdentifier: indexToOperationIdentifier(3),
Account: addressToAccountIdentifier("erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu"),
Amount: extension.valueToNativeAmount("-10000000000000000"),
Status: &opStatusSuccess,
},
{
Type: opTransfer,
OperationIdentifier: indexToOperationIdentifier(4),
Account: addressToAccountIdentifier("erd1qqqqqqqqqqqqqpgqc4vdnqgc48ww26ljxqe2flgl86jewg0nq6uqna2ymj"),
Amount: extension.valueToNativeAmount("10000000000000000"),
Status: &opStatusSuccess,
},
},
Metadata: extractTransactionMetadata(blocks[0].MiniBlocks[0].Transactions[0]),
}

require.Equal(t, expectedTx, txs[0])
}

func TestTransactionsTransformer_TransformBlockTxsHavingESDTIssue(t *testing.T) {
networkProvider := testscommon.NewNetworkProviderMock()
networkProvider.MockCustomCurrencies = []resources.Currency{{Symbol: "FOO-6d28db"}}
Expand Down
18 changes: 18 additions & 0 deletions systemtests/broadcast_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from systemtests.config import CONFIGURATIONS, Configuration

CONTRACT_PATH_ADDER = Path(__file__).parent / "adder.wasm"
CONTRACT_PATH_DUMMY = Path(__file__).parent / "dummy.wasm"


def main():
Expand Down Expand Up @@ -147,6 +148,12 @@ def main():
amount=1000000000000000000
))

# Direct contract deployment with MoveBalance
controller.send(controller.create_contract_deployment_with_move_balance(
sender=accounts.get_user(shard=0, index=0),
amount=10000000000000000
))


class BunchOfAccounts:
def __init__(self, configuration: Configuration) -> None:
Expand Down Expand Up @@ -362,6 +369,17 @@ def create_relayed_v3_with_a_few_inner_move_balances(self, relayer: "Account", s

return transaction

def create_contract_deployment_with_move_balance(self, sender: "Account", amount: int) -> Transaction:
transaction = self.contracts_transactions_factory.create_transaction_for_deploy(
sender=sender.address,
bytecode=CONTRACT_PATH_DUMMY,
gas_limit=5000000,
arguments=[0],
native_transfer_amount=amount
)

return transaction

def send_multiple(self, transactions: List[Transaction]):
for transaction in transactions:
self._apply_nonce(transaction)
Expand Down
Binary file added systemtests/dummy.wasm
Binary file not shown.

0 comments on commit f64dd9e

Please sign in to comment.