Skip to content

Commit

Permalink
add tx test with unsafeRandom
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarak Ben Youssef committed Aug 4, 2023
1 parent d770012 commit f061d3d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions emulator/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2116,3 +2116,37 @@ func TestRollbackTransaction(t *testing.T) {
IncrementHelper(t, b, adapter, counterAddress, addTwoScript, 2)

}

// TestTransactionWithCadenceRandom checks Cadence's random function works
func TestTransactionWithCadenceRandom(t *testing.T) {
b, adapter := setupTransactionTests(t)

code := `
transaction {
prepare() {
assert(unsafeRandom() >= 0)
}
}
`
callRandomTx := flowsdk.NewTransaction().
SetGasLimit(flowgo.DefaultMaxTransactionGasLimit).
SetScript([]byte(code)).
SetProposalKey(b.ServiceKey().Address, b.ServiceKey().Index, b.ServiceKey().SequenceNumber).
SetPayer(b.ServiceKey().Address)

signer, err := b.ServiceKey().Signer()
require.NoError(t, err)

err = callRandomTx.SignEnvelope(b.ServiceKey().Address, b.ServiceKey().Index, signer)
require.NoError(t, err)

err = adapter.SendTransaction(context.Background(), *callRandomTx)
assert.NoError(t, err)

result, err := b.ExecuteNextTransaction()
assert.NoError(t, err)
AssertTransactionSucceeded(t, result)

_, err = b.CommitBlock()
assert.NoError(t, err)
}

0 comments on commit f061d3d

Please sign in to comment.