Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"source": "./contracts/FlowTransactionScheduler.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7",
"testing": "0000000000000001"
"testing": "0000000000000007"
}
},
"FlowTransactionSchedulerUtils": {
"source": "./contracts/FlowTransactionSchedulerUtils.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7",
"testing": "0000000000000001"
"testing": "0000000000000007"
}
},
"FlowClusterQC": {
Expand Down Expand Up @@ -158,7 +158,7 @@
"source": "./contracts/testContracts/TestFlowScheduledTransactionHandler.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7",
"testing": "0000000000000001"
"testing": "0000000000000007"
}
}
},
Expand All @@ -181,6 +181,15 @@
"testnet": "9a0766d93b6608b7"
}
},
"FungibleTokenMetadataViews": {
"source": "mainnet://f233dcee88fe0abe.FungibleTokenMetadataViews",
"hash": "dff704a6e3da83997ed48bcd244aaa3eac0733156759a37c76a58ab08863016a",
"aliases": {
"emulator": "ee82856bf20e2aa6",
"mainnet": "f233dcee88fe0abe",
"testnet": "9a0766d93b6608b7"
}
},
"MetadataViews": {
"source": "mainnet://1d7e57aa55817448.MetadataViews",
"hash": "9032f46909e729d26722cbfcee87265e4f81cd2912e936669c0e6b510d007e81",
Expand Down Expand Up @@ -221,12 +230,5 @@
"address": "f8d6e0586b0a20c7",
"key": "aff3a277caf2bdd6582c156ae7b07dbca537da7833309de88e56987faa2c0f1b"
}
},
"deployments": {
"emulator": {
"emulator-account": [
"TestFlowScheduledTransactionHandler"
]
}
}
}
107 changes: 68 additions & 39 deletions tests/scheduled_transaction_test_helpers.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ access(all) fun scheduleTransaction(
) {
var tx = Test.Transaction(
code: Test.readFile("../transactions/transactionScheduler/schedule_transaction.cdc"),
authorizers: [serviceAccount.address],
signers: [serviceAccount],
authorizers: [admin.address],
signers: [admin],
arguments: [timestamp, fee, effort, priority, data],
)
var result = Test.executeTransaction(tx)
Expand Down Expand Up @@ -93,8 +93,8 @@ access(all) fun scheduleTransactionByHandler(
) {
var tx = Test.Transaction(
code: Test.readFile("../transactions/transactionScheduler/schedule_transaction_by_handler.cdc"),
authorizers: [serviceAccount.address],
signers: [serviceAccount],
authorizers: [admin.address],
signers: [admin],
arguments: [handlerTypeIdentifier, handlerUUID, timestamp, fee, effort, priority, data],
)
var result = Test.executeTransaction(tx)
Expand All @@ -118,8 +118,8 @@ access(all) fun scheduleTransactionByHandler(
access(all) fun cancelTransaction(id: UInt64, failWithErr: String?) {
var tx = Test.Transaction(
code: Test.readFile("../transactions/transactionScheduler/cancel_transaction.cdc"),
authorizers: [serviceAccount.address],
signers: [serviceAccount],
authorizers: [admin.address],
signers: [admin],
arguments: [id],
)
var result = Test.executeTransaction(tx)
Expand All @@ -140,8 +140,8 @@ access(all) fun processTransactions(): Test.TransactionResult {
let processTransactionCode = Test.readFile("../transactions/transactionScheduler/admin/process_scheduled_transactions.cdc")
let processTx = Test.Transaction(
code: processTransactionCode,
authorizers: [serviceAccount.address],
signers: [serviceAccount],
authorizers: [admin.address],
signers: [admin],
arguments: []
)
let processResult = Test.executeTransaction(processTx)
Expand All @@ -157,8 +157,8 @@ access(all) fun executeScheduledTransaction(
let executeTransactionCode = Test.readFile("../transactions/transactionScheduler/admin/execute_transaction.cdc")
let executeTx = Test.Transaction(
code: executeTransactionCode,
authorizers: [serviceAccount.address],
signers: [serviceAccount],
authorizers: [admin.address],
signers: [admin],
arguments: [id]
)
var result = Test.executeTransaction(executeTx)
Expand Down Expand Up @@ -195,8 +195,8 @@ access(all) fun setConfigDetails(
let setConfigDetailsCode = Test.readFile("../transactions/transactionScheduler/admin/set_config_details.cdc")
let setConfigDetailsTx = Test.Transaction(
code: setConfigDetailsCode,
authorizers: [serviceAccount.address],
signers: [serviceAccount],
authorizers: [admin.address],
signers: [admin],
arguments: [maximumIndividualEffort,
minimumExecutionEffort,
slotSharedEffortLimit,
Expand Down Expand Up @@ -327,7 +327,7 @@ access(all) fun getPendingQueue(): [UInt64] {
access(all) fun getManagedTxStatus(_ id: UInt64): UInt8? {
var result = _executeScript(
"../transactions/transactionScheduler/scripts/manager/get_managed_tx_status.cdc",
[serviceAccount.address, id]
[admin.address, id]
)
Test.expect(result, Test.beSucceeded())
return result.returnValue as? UInt8
Expand All @@ -336,7 +336,7 @@ access(all) fun getManagedTxStatus(_ id: UInt64): UInt8? {
access(all) fun getManagedTxData(_ id: UInt64): FlowTransactionScheduler.TransactionData? {
var result = _executeScript(
"../transactions/transactionScheduler/scripts/manager/get_tx_data.cdc",
[serviceAccount.address, id]
[admin.address, id]
)
Test.expect(result, Test.beSucceeded())
return result.returnValue as? FlowTransactionScheduler.TransactionData
Expand All @@ -345,7 +345,7 @@ access(all) fun getManagedTxData(_ id: UInt64): FlowTransactionScheduler.Transac
access(all) fun getManagedTxIDsByTimestamp(_ timestamp: UFix64): [UInt64] {
var result = _executeScript(
"../transactions/transactionScheduler/scripts/manager/get_tx_ids_by_timestamp.cdc",
[serviceAccount.address, timestamp]
[admin.address, timestamp]
)
Test.expect(result, Test.beSucceeded())
return result.returnValue as! [UInt64]
Expand All @@ -354,7 +354,7 @@ access(all) fun getManagedTxIDsByTimestamp(_ timestamp: UFix64): [UInt64] {
access(all) fun getManagedTxIDsByTimestampRange(startTimestamp: UFix64, endTimestamp: UFix64): {UFix64: [UInt64]} {
var result = _executeScript(
"../transactions/transactionScheduler/scripts/manager/get_tx_ids_by_time_range.cdc",
[serviceAccount.address, startTimestamp, endTimestamp]
[admin.address, startTimestamp, endTimestamp]
)
Test.expect(result, Test.beSucceeded())
return result.returnValue! as! {UFix64: [UInt64]}
Expand All @@ -363,7 +363,7 @@ access(all) fun getManagedTxIDsByTimestampRange(startTimestamp: UFix64, endTimes
access(all) fun getManagedTxIDsByHandler(handlerTypeIdentifier: String, handlerUUID: UInt64?): [UInt64] {
var result = _executeScript(
"../transactions/transactionScheduler/scripts/manager/get_tx_ids_by_handler.cdc",
[serviceAccount.address, handlerTypeIdentifier, handlerUUID]
[admin.address, handlerTypeIdentifier, handlerUUID]
)
Test.expect(result, Test.beSucceeded())
return result.returnValue as! [UInt64]
Expand All @@ -372,7 +372,7 @@ access(all) fun getManagedTxIDsByHandler(handlerTypeIdentifier: String, handlerU
access(all) fun getManagedTxIDs(): [UInt64] {
var result = _executeScript(
"../transactions/transactionScheduler/scripts/manager/get_manager_tx_ids.cdc",
[serviceAccount.address]
[admin.address]
)
Test.expect(result, Test.beSucceeded())
return result.returnValue as! [UInt64]
Expand All @@ -381,7 +381,7 @@ access(all) fun getManagedTxIDs(): [UInt64] {
access(all) fun getHandlerTypeIdentifiers(): {String: [UInt64]} {
var result = _executeScript(
"../transactions/transactionScheduler/scripts/manager/get_handler_types.cdc",
[serviceAccount.address]
[admin.address]
)
Test.expect(result, Test.beSucceeded())
return result.returnValue! as! {String: [UInt64]}
Expand All @@ -390,7 +390,7 @@ access(all) fun getHandlerTypeIdentifiers(): {String: [UInt64]} {
access(all) fun getHandlerViews(handlerTypeIdentifier: String, handlerUUID: UInt64?): [Type] {
var result = _executeScript(
"../transactions/transactionScheduler/scripts/manager/get_handler_views.cdc",
[serviceAccount.address, handlerTypeIdentifier, handlerUUID]
[admin.address, handlerTypeIdentifier, handlerUUID]
)
Test.expect(result, Test.beSucceeded())
return result.returnValue as! [Type]
Expand All @@ -399,7 +399,7 @@ access(all) fun getHandlerViews(handlerTypeIdentifier: String, handlerUUID: UInt
access(all) fun getHandlerViewsFromTransactionID(_ id: UInt64): [Type] {
var result = _executeScript(
"../transactions/transactionScheduler/scripts/manager/get_handler_views_from_tx_id.cdc",
[serviceAccount.address, id]
[admin.address, id]
)
Test.expect(result, Test.beSucceeded())
return result.returnValue as! [Type]
Expand All @@ -408,7 +408,7 @@ access(all) fun getHandlerViewsFromTransactionID(_ id: UInt64): [Type] {
access(all) fun resolveHandlerView(handlerTypeIdentifier: String, handlerUUID: UInt64?, viewType: Type): AnyStruct? {
var result = _executeScript(
"../transactions/transactionScheduler/scripts/manager/resolve_handler_view.cdc",
[serviceAccount.address, handlerTypeIdentifier, handlerUUID, viewType]
[admin.address, handlerTypeIdentifier, handlerUUID, viewType]
)
Test.expect(result, Test.beSucceeded())
return result.returnValue as? AnyStruct
Expand All @@ -417,12 +417,51 @@ access(all) fun resolveHandlerView(handlerTypeIdentifier: String, handlerUUID: U
access(all) fun resolveHandlerViewFromTransactionID(id: UInt64, viewType: Type): AnyStruct? {
var result = _executeScript(
"../transactions/transactionScheduler/scripts/manager/resolve_handler_view_from_tx_id.cdc",
[serviceAccount.address, id, viewType]
[admin.address, id, viewType]
)
Test.expect(result, Test.beSucceeded())
return result.returnValue as? AnyStruct
}

access(all) fun upgradeSchedulerContract() {
var schedulerCode = Test.readFile("../contracts/FlowTransactionScheduler.cdc")
schedulerCode = schedulerCode.replaceAll(of: "\"FungibleToken\"", with: "FungibleToken from 0x0000000000000002")
schedulerCode = schedulerCode.replaceAll(of: "\"FlowToken\"", with: "FlowToken from 0x0000000000000003")
schedulerCode = schedulerCode.replaceAll(of: "\"FlowFees\"", with: "FlowFees from 0x0000000000000004")
schedulerCode = schedulerCode.replaceAll(of: "\"FlowStorageFees\"", with: "FlowStorageFees from 0x0000000000000001")
schedulerCode = schedulerCode.replaceAll(of: "\"ViewResolver\"", with: "ViewResolver from 0x0000000000000001")

var upgradeTx = Test.Transaction(
code: Test.readFile("./transactions/upgrade_contract.cdc"),
authorizers: [admin.address],
signers: [admin],
arguments: ["FlowTransactionScheduler", schedulerCode],
)

// Upgrade the FlowTransactionScheduler contract
var upgradeResult = Test.executeTransaction(
upgradeTx,
)
Test.expect(upgradeResult, Test.beSucceeded())
}

access(all) fun upgradeSchedulerUtilsContract() {
var schedulerUtilsCode = Test.readFile("../contracts/FlowTransactionSchedulerUtils.cdc")
schedulerUtilsCode = schedulerUtilsCode.replaceAll(of: "\"FlowTransactionScheduler\"", with: "FlowTransactionScheduler from 0x0000000000000007")
schedulerUtilsCode = schedulerUtilsCode.replaceAll(of: "\"FlowToken\"", with: "FlowToken from 0x0000000000000003")

var upgradeTx = Test.Transaction(
code: Test.readFile("./transactions/upgrade_contract.cdc"),
authorizers: [admin.address],
signers: [admin],
arguments: ["FlowTransactionSchedulerUtils", schedulerUtilsCode],
)
var upgradeResult = Test.executeTransaction(
upgradeTx,
)
Test.expect(upgradeResult, Test.beSucceeded())
}

access(all) fun getTimestamp(): UFix64 {
var timestamp = _executeScript(
"./scripts/get_timestamp.cdc",
Expand Down Expand Up @@ -452,24 +491,14 @@ fun _executeScript(_ path: String, _ args: [AnyStruct]): Test.ScriptResult {
return Test.executeScript(Test.readFile(path), args)
}

access(all) fun upgradeSchedulerContract() {
var schedulerCode = Test.readFile("../contracts/FlowTransactionScheduler.cdc")
schedulerCode = schedulerCode.replaceAll(of: "\"FungibleToken\"", with: "FungibleToken from 0x0000000000000002")
schedulerCode = schedulerCode.replaceAll(of: "\"FlowToken\"", with: "FlowToken from 0x0000000000000003")
schedulerCode = schedulerCode.replaceAll(of: "\"FlowFees\"", with: "FlowFees from 0x0000000000000004")
schedulerCode = schedulerCode.replaceAll(of: "\"FlowStorageFees\"", with: "FlowStorageFees from 0x0000000000000001")
schedulerCode = schedulerCode.replaceAll(of: "\"ViewResolver\"", with: "ViewResolver from 0x0000000000000001")
access(all) fun fundAccountWithFlow(to: Address, amount: UFix64) {

var upgradeTx = Test.Transaction(
code: Test.readFile("./transactions/upgrade_contract.cdc"),
var tx = Test.Transaction(
code: Test.readFile("../transactions/flowToken/transfer_tokens.cdc"),
authorizers: [serviceAccount.address],
signers: [serviceAccount],
arguments: ["FlowTransactionScheduler", schedulerCode],
arguments: [amount, to],
)

// Upgrade the FlowTransactionScheduler contract
var upgradeResult = Test.executeTransaction(
upgradeTx,
)
Test.expect(upgradeResult, Test.beSucceeded())
var result = Test.executeTransaction(tx)
Test.expect(result, Test.beSucceeded())
}
2 changes: 1 addition & 1 deletion tests/scripts/get_pending_queue.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "FlowTransactionScheduler"

access(all) fun main(): [UInt64] {

let schedulerAccount = getAuthAccount<auth(BorrowValue) &Account>(0x0000000000000001)
let schedulerAccount = getAuthAccount<auth(BorrowValue) &Account>(0x0000000000000007)

let scheduler = schedulerAccount.storage.borrow<auth(FlowTransactionScheduler.Process) &FlowTransactionScheduler.SharedScheduler>(from: FlowTransactionScheduler.storagePath)
?? panic("Could not borrow FlowTransactionScheduler")
Expand Down
29 changes: 18 additions & 11 deletions tests/transactionScheduler_events_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ access(all) var accountBalanceBefore: UFix64 = 0.0
access(all)
fun setup() {

upgradeSchedulerContract()

var err = Test.deployContract(
name: "FlowTransactionScheduler",
path: "../contracts/FlowTransactionScheduler.cdc",
arguments: []
)
Test.expect(err, Test.beNil())

err = Test.deployContract(
name: "FlowTransactionSchedulerUtils",
path: "../contracts/FlowTransactionSchedulerUtils.cdc",
arguments: []
Expand All @@ -33,6 +38,8 @@ fun setup() {
)
Test.expect(err, Test.beNil())

fundAccountWithFlow(to: admin.address, amount: 10000.0)

startingHeight = getCurrentBlockHeight()

}
Expand All @@ -46,7 +53,7 @@ access(all) fun testTransactionScheduleEventAndData() {
let currentTime = getTimestamp()
let timeInFuture = currentTime + futureDelta

accountBalanceBefore = getBalance(account: serviceAccount.address)
accountBalanceBefore = getBalance(account: admin.address)
feesBalanceBefore = getFeesBalance()

// Schedule high priority transaction
Expand All @@ -69,8 +76,8 @@ access(all) fun testTransactionScheduleEventAndData() {
Test.assertEqual(timeInFuture, scheduledEvent.timestamp!)
Test.assert(scheduledEvent.executionEffort == basicEffort, message: "incorrect execution effort")
Test.assertEqual(feeAmount, scheduledEvent.fees!)
Test.assertEqual(serviceAccount.address, scheduledEvent.transactionHandlerOwner!)
Test.assertEqual("A.0000000000000001.TestFlowScheduledTransactionHandler.Handler", scheduledEvent.transactionHandlerTypeIdentifier!)
Test.assertEqual(admin.address, scheduledEvent.transactionHandlerOwner!)
Test.assertEqual("A.0000000000000007.TestFlowScheduledTransactionHandler.Handler", scheduledEvent.transactionHandlerTypeIdentifier!)
Test.assertEqual(TestFlowScheduledTransactionHandler.HandlerPublicPath, scheduledEvent.transactionHandlerPublicPath!)

let transactionID = scheduledEvent.id as UInt64
Expand All @@ -85,8 +92,8 @@ access(all) fun testTransactionScheduleEventAndData() {
Test.assertEqual(feeAmount, transactionData!.fees)
Test.assertEqual(basicEffort, transactionData!.executionEffort)
Test.assertEqual(statusScheduled, transactionData!.status.rawValue)
Test.assertEqual(serviceAccount.address, transactionData!.handlerAddress)
Test.assertEqual("A.0000000000000001.TestFlowScheduledTransactionHandler.Handler", transactionData!.handlerTypeIdentifier)
Test.assertEqual(admin.address, transactionData!.handlerAddress)
Test.assertEqual("A.0000000000000007.TestFlowScheduledTransactionHandler.Handler", transactionData!.handlerTypeIdentifier)

// invalid timeframe should return empty dictionary
var transactions = getTransactionsForTimeframe(startTimestamp: timeInFuture, endTimestamp: timeInFuture - 1.0)
Expand Down Expand Up @@ -116,7 +123,7 @@ access(all) fun testScheduledTransactionCancelationEvents() {
var currentTime = getTimestamp()
var timeInFuture = currentTime + futureDelta

var balanceBefore = getBalance(account: serviceAccount.address)
var balanceBefore = getBalance(account: admin.address)

// Cancel invalid transaction should fail
cancelTransaction(
Expand Down Expand Up @@ -148,8 +155,8 @@ access(all) fun testScheduledTransactionCancelationEvents() {
Test.assertEqual(mediumPriority, canceledEvent.priority)
Test.assertEqual(feeAmount/UFix64(2.0), canceledEvent.feesReturned)
Test.assertEqual(feeAmount/UFix64(2.0), canceledEvent.feesDeducted)
Test.assertEqual(serviceAccount.address, canceledEvent.transactionHandlerOwner)
Test.assertEqual("A.0000000000000001.TestFlowScheduledTransactionHandler.Handler", canceledEvent.transactionHandlerTypeIdentifier!)
Test.assertEqual(admin.address, canceledEvent.transactionHandlerOwner)
Test.assertEqual("A.0000000000000007.TestFlowScheduledTransactionHandler.Handler", canceledEvent.transactionHandlerTypeIdentifier!)

// Make sure the status is canceled
var status = getStatus(id: transactionToCancel)
Expand All @@ -161,7 +168,7 @@ access(all) fun testScheduledTransactionCancelationEvents() {
Test.assertEqual(UInt64(mediumPriorityMaxEffort), effort!)

// Assert that the new balance reflects the refunds
Test.assertEqual(balanceBefore - feeAmount/UFix64(2.0), getBalance(account: serviceAccount.address))
Test.assertEqual(balanceBefore - feeAmount/UFix64(2.0), getBalance(account: admin.address))
Test.assertEqual(feesBalanceBefore + feeAmount/UFix64(2.0), getFeesBalance())
}

Expand Down
Loading
Loading