Skip to content

Commit

Permalink
Bug fix swap participation + added automated test for deposit parsing
Browse files Browse the repository at this point in the history
* Added a parsing test got Deposit
* Bug Fix with Swap's participant address
  • Loading branch information
Vivek Teega committed Apr 17, 2023
1 parent d794e65 commit ba80ae4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,4 +1269,5 @@ def parse_flodata(text, blockinfo, net):

return outputreturn('continuos-event-token-swap-incorporation', f"{contract_token}", f"{contract_name}", f"{contract_address}", f"{clean_text}", f"{contract_conditions['subtype']}", f"{contract_conditions['accepting_token']}", f"{contract_conditions['selling_token']}", f"{contract_conditions['priceType']}", f"{contract_conditions['price']}", stateF_mapping, f"{contract_conditions['oracle_address']}")

return outputreturn('noise')
return outputreturn('noise')

15 changes: 15 additions & 0 deletions test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ def test_onetimeevent_externaltrigger_creation(self):
}
self.assertEqual(result, expected_result)

def test_tokenswap_deposits(self):
text = 'Deposit 1 bioscope# to swap-rupee-bioscope-1@ its FLO address being oTzrcpLPRXsejSdYQ3XN6V4besrAPuJQrk$ with deposit-conditions: (1) expiryTime= Thu Apr 13 2023 21:45:00 GMT+0530'
result = parsing.parse_flodata(text, TestParsing.blockinfo_stub, 'testnet')
expected_result = {
'type': 'smartContractDeposit',
'tokenIdentification': 'bioscope',
'depositAmount': 1.0,
'contractName': 'swap-rupee-bioscope-1',
'flodata': 'Deposit 1 bioscope# to swap-rupee-bioscope-1@ its FLO address being oTzrcpLPRXsejSdYQ3XN6V4besrAPuJQrk$ with deposit-conditions: (1) expiryTime= Thu Apr 13 2023 21:45:00 GMT+0530',
'depositConditions': {
'expiryTime': 'thu apr 13 2023 21:45:00 gmt+0530'
},
'stateF': False}
self.assertEqual(result, expected_result)


if __name__ == '__main__':
unittest.main()
13 changes: 7 additions & 6 deletions tracktokens_smartcontracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,10 @@ def processBlock(blockindex=None, blockhash=None):
blockhash = response['blockHash']

blockinfo = newMultiRequest(f"block/{blockhash}")
pause_index = [2211699, 2211700, 2211701, 2170000, 2468107, 2468108, 2489267]
pause_index = [2211699, 2211700, 2211701, 2170000, 2468107, 2468108, 2489267, 2449017]
if blockindex in pause_index:
print(f'Paused at {blockindex}')

# Check smartContracts which will be triggered locally, and not by the contract committee
#checkLocaltriggerContracts(blockinfo)
# Check if any deposits have to be returned
Expand Down Expand Up @@ -704,7 +705,6 @@ def checkLocal_expiry_trigger_deposit(blockinfo):
close_expire_contract(contractStructure, 'expired', query.transactionHash, query.blockNumber, 'query.blockHash', 'query.incorporationDate', blockinfo['time'], 'query.closeDate', query.time, query.activity, query.contractName, query.contractAddress, query.contractType, query.tokens_db, query.parsed_data, blockinfo['height'])

elif 'payeeAddress' in contractStructure: # Internal trigger contract type

tokenAmount_sum = connection.execute('SELECT IFNULL(sum(tokenAmount), 0) FROM contractparticipants').fetchall()[0][0]
# maximumsubscription check, if reached then trigger the contract
if 'maximumsubscriptionamount' in contractStructure:
Expand Down Expand Up @@ -1255,9 +1255,11 @@ def processTransaction(transaction_data, parsed_data, blockinfo):

# todo - what is the role of the next line? cleanup if not useful
available_deposits = active_contract_deposits[:]

available_deposit_sum = contract_session.query(func.sum(ContractDeposits.depositBalance)).filter(ContractDeposits.id.in_(subquery)).filter(ContractDeposits.status != 'deposit-return').filter(ContractDeposits.status == 'active').all()
available_deposit_sum = float(available_deposit_sum[0][0])
if available_deposit_sum[0][0] is None:
available_deposit_sum = 0
else:
available_deposit_sum = float(available_deposit_sum[0][0])

'''consumed_deposit_ids = contract_session.query(ConsumedInfo.id_deposittable).all()
available_deposit_sum = 0
Expand Down Expand Up @@ -1364,7 +1366,7 @@ def processTransaction(transaction_data, parsed_data, blockinfo):
return 0

# ContractParticipationTable
contract_session.add(ContractParticipants(participantAddress = transaction_data['receiverAddress'], tokenAmount= parsed_data['tokenAmount'], userChoice= swapPrice, transactionHash= transaction_data['txid'], blockNumber= blockinfo['height'], blockHash= blockinfo['hash'], winningAmount = swapAmount))
contract_session.add(ContractParticipants(participantAddress = transaction_data['senderAddress'], tokenAmount= parsed_data['tokenAmount'], userChoice= swapPrice, transactionHash= transaction_data['txid'], blockNumber= blockinfo['height'], blockHash= blockinfo['hash'], winningAmount = swapAmount))

add_contract_transaction_history(contract_name=parsed_data['contractName'], contract_address=outputlist[0], transactionType='participation', transactionSubType='swap', sourceFloAddress=inputlist[0], destFloAddress=outputlist[0], transferAmount=swapAmount, blockNumber=blockinfo['height'], blockHash=blockinfo['hash'], blocktime=blockinfo['time'], transactionHash=transaction_data['txid'], jsonData=json.dumps(transaction_data), parsedFloData=json.dumps(parsed_data))

Expand Down Expand Up @@ -1504,7 +1506,6 @@ def processTransaction(transaction_data, parsed_data, blockinfo):
# todo Rule 49 - If the contract name hasn't been taken before, check if the contract type is an authorized type by the system
if parsed_data['contractType'] == 'one-time-event':
logger.info("Smart contract is of the type one-time-event")

# either userchoice or payeeAddress condition should be present. Check for it
if 'userchoices' not in parsed_data['contractConditions'] and 'payeeAddress' not in parsed_data['contractConditions']:
rejectComment = f"Either userchoice or payeeAddress should be part of the Contract conditions.\nSmart contract incorporation on transaction {transaction_data['txid']} rejected"
Expand Down

0 comments on commit ba80ae4

Please sign in to comment.