@@ -1008,3 +1008,36 @@ def test_contains() -> None:
10081008 contract = MyContract ()
10091009
10101010 contract .approval_program ()
1011+
1012+
1013+ def test_globals (context : AlgopyTestContext ) -> None :
1014+ creator = context .any .account ()
1015+ app = context .any .application (creator = creator )
1016+ txn1 = context .any .txn .application_call (app_id = app )
1017+ with context .txn .create_group (gtxns = [txn1 ]):
1018+ first_group_id = algopy .Global .group_id
1019+ first_timestamp = algopy .Global .latest_timestamp
1020+ assert first_group_id .length == 32
1021+ assert first_timestamp != 0
1022+ assert algopy .Global .group_size == 1
1023+ assert algopy .Global .round == 1
1024+ assert algopy .Global .caller_application_id == 0
1025+ assert algopy .Global .creator_address == creator
1026+ assert algopy .Global .current_application_id == app
1027+ assert algopy .Global .current_application_address == app .address
1028+
1029+ txn2 = context .any .txn .payment ()
1030+ txn3 = context .any .txn .application_call ()
1031+ caller = context .any .application ()
1032+ context .ledger .patch_global_fields (caller_application_id = caller .id )
1033+ with context .txn .create_group (gtxns = [txn2 , txn3 ]):
1034+ second_group_id = algopy .Global .group_id
1035+ second_timestamp = algopy .Global .latest_timestamp
1036+ assert second_group_id .length == 32
1037+ assert algopy .Global .group_size == 2
1038+ assert algopy .Global .round == 2
1039+ assert algopy .Global .caller_application_id == caller .id
1040+ assert algopy .Global .caller_application_address == caller .address
1041+
1042+ assert first_group_id != second_group_id , "expected unique group ids"
1043+ assert first_timestamp <= second_timestamp , "expected unique group ids"
0 commit comments