@@ -2116,3 +2116,38 @@ func TestRollbackTransaction(t *testing.T) {
21162116 IncrementHelper (t , b , adapter , counterAddress , addTwoScript , 2 )
21172117
21182118}
2119+
2120+ // TestTransactionWithCadenceRandom checks Cadence's random function works
2121+ // within a transaction
2122+ func TestTransactionWithCadenceRandom (t * testing.T ) {
2123+ b , adapter := setupTransactionTests (t )
2124+
2125+ code := `
2126+ transaction {
2127+ prepare() {
2128+ assert(unsafeRandom() >= 0)
2129+ }
2130+ }
2131+ `
2132+ callRandomTx := flowsdk .NewTransaction ().
2133+ SetGasLimit (flowgo .DefaultMaxTransactionGasLimit ).
2134+ SetScript ([]byte (code )).
2135+ SetProposalKey (b .ServiceKey ().Address , b .ServiceKey ().Index , b .ServiceKey ().SequenceNumber ).
2136+ SetPayer (b .ServiceKey ().Address )
2137+
2138+ signer , err := b .ServiceKey ().Signer ()
2139+ require .NoError (t , err )
2140+
2141+ err = callRandomTx .SignEnvelope (b .ServiceKey ().Address , b .ServiceKey ().Index , signer )
2142+ require .NoError (t , err )
2143+
2144+ err = adapter .SendTransaction (context .Background (), * callRandomTx )
2145+ assert .NoError (t , err )
2146+
2147+ result , err := b .ExecuteNextTransaction ()
2148+ assert .NoError (t , err )
2149+ AssertTransactionSucceeded (t , result )
2150+
2151+ _ , err = b .CommitBlock ()
2152+ assert .NoError (t , err )
2153+ }
0 commit comments