Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed May 20, 2024
1 parent f61acf7 commit eefc095
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ class TestChain : DYDXChainTransactionsProtocol {
var cancelOrderResponse: String? = null
var depositResponse: String? = null
var withdrawResponse: String? = null
var signCompliancePayload: String? = null

var transactionCallback: ((response: String?) -> Unit)? = null

Expand Down Expand Up @@ -377,10 +378,22 @@ class TestChain : DYDXChainTransactionsProtocol {
withdraw(paramsInJson!!, callback)
}

TransactionType.SignCompliancePayload -> {
signCompliancePayload(paramsInJson!!, callback)
}

else -> {}
}
}

fun signCompliancePayload(json: String, callback: (response: String?) -> Unit) {
if (signCompliancePayload != null) {
callback(signCompliancePayload)
} else {
callback(dummyError)
}
}

fun getHeight(callback: (response: String?) -> Unit) {
if (heightResponse != null) {
callback(heightResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,36 @@ class V4RestrictionsTests {
fun testGeoEndpointHandling() {
reset()

val testAddress = "cosmos1fq8q55896ljfjj7v3x0qd0z3sr78wmes940uhm"
testChain!!.signCompliancePayload = """
{
"signedMessage": "1",
"publicKey": "1",
"timestamp": "2024-05-14T20:40:00.415Z"
}
""".trimIndent()

testRest?.setResponse(
"https://indexer.v4staging.dydx.exchange/v4/compliance/geoblock",
"""
{
"status": "CLOSE_ONLY",
"reason": null,
"updatedAt": "2024-05-14T20:40:00.415Z"
}
""".trimIndent(),
)

setStateMachineConnected(stateManager)
val testAddress = "cosmos1fq8q55896ljfjj7v3x0qd0z3sr78wmes940uhm"
stateManager.setAddresses(null, testAddress)

testRest?.setResponse(
"https://indexer.v4staging.dydx.exchange/v4/compliance/screen",
"https://indexer.v4staging.dydx.exchange/v4/compliance/screen/$testAddress",
"""
{
"restricted": false
"status": "CLOSE_ONLY",
"reason": null,
"updatedAt": "2024-05-14T20:40:00.415Z"
}
""".trimIndent(),
)
Expand All @@ -171,9 +193,6 @@ class V4RestrictionsTests {
""".trimIndent(),
)

setStateMachineConnected(stateManager)
stateManager.setAddresses(null, testAddress)

stateManager.triggerCompliance(ComplianceAction.CONNECT) { successful, error, data ->
print("")
}
Expand All @@ -190,10 +209,11 @@ class V4RestrictionsTests {
"Expected different updatedAt",
)

// expires at is 7 days in advance
assertEquals(
"2024-05-27T20:40:00.415Z",
"2024-05-21T20:40:00.415Z",
stateManager.adaptor?.stateMachine?.state?.compliance?.expiresAt,
"Expected different updatedAt",
"Expected different expires at",
)
}
}

0 comments on commit eefc095

Please sign in to comment.