Skip to content

Commit 5d37df3

Browse files
tmp
1 parent bad7649 commit 5d37df3

File tree

1 file changed

+44
-76
lines changed

1 file changed

+44
-76
lines changed

src/choreo/test_choreo.c

Lines changed: 44 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ insert_vote_state_into_funk_txn( fd_funk_t * funk,
191191
FD_TEST( fd_vote_state_versioned_encode( vote_state_versioned, &encode_ctx )==0 );
192192
}
193193

194-
void
194+
ulong
195195
voter_vote_for_slot( fd_wksp_t * wksp,
196196
fd_tower_t * tower,
197197
fd_funk_t * funk,
198198
ulong vote_slot,
199199
ulong slot,
200200
voter_t * voter ) {
201201
// Update tower with vote
202-
fd_tower_vote( tower, vote_slot );
202+
ulong root = fd_tower_vote( tower, vote_slot );
203203

204204
// Convert updated tower to vote state
205205
fd_vote_state_versioned_t * vote_state_versioned = tower_to_vote_state( wksp, tower, voter );
@@ -209,6 +209,8 @@ voter_vote_for_slot( fd_wksp_t * wksp,
209209

210210
// Insert updated vote state into funk
211211
insert_vote_state_into_funk_txn( funk, funk_txn, &voter->pubkey, vote_state_versioned );
212+
213+
return root;
212214
}
213215

214216
fd_epoch_t *
@@ -318,7 +320,7 @@ test_vote_simple( fd_wksp_t * wksp ) {
318320
init_vote_accounts( voters, voter_cnt );
319321

320322
ulong stakes[] = {10000, 10000, 10000, 10000, 10000};
321-
fd_epoch_t * epoch = mock_epoch(wksp, voter_cnt, stakes, voters);
323+
fd_epoch_t * epoch = mock_epoch( wksp, voter_cnt, stakes, voters );
322324

323325
/**********************************************************************/
324326
/* Setup funk_txns for each slot with vote account funk records */
@@ -413,7 +415,7 @@ test_vote_switch_check( fd_wksp_t * wksp ) {
413415
init_vote_accounts( voters, voter_cnt );
414416

415417
ulong stakes[] = {10000, 10000, 10000, 10000, 10000};
416-
fd_epoch_t * epoch = mock_epoch(wksp, voter_cnt, stakes, voters);
418+
fd_epoch_t * epoch = mock_epoch( wksp, voter_cnt, stakes, voters );
417419

418420
/**********************************************************************/
419421
/* Setup funk_txns for each slot with vote account funk records */
@@ -535,7 +537,7 @@ test_vote_switch_check_4forks( fd_wksp_t * wksp ) {
535537
init_vote_accounts( voters, voter_cnt );
536538

537539
ulong stakes[] = {10000, 10000, 10000, 20001};
538-
fd_epoch_t * epoch = mock_epoch(wksp, voter_cnt, stakes, voters);
540+
fd_epoch_t * epoch = mock_epoch( wksp, voter_cnt, stakes, voters );
539541

540542
/**********************************************************************/
541543
/* Setup funk_txns for each slot with vote account funk records */
@@ -651,7 +653,7 @@ test_vote_lockout_check( fd_wksp_t * wksp ) {
651653
init_vote_accounts( voters, voter_cnt );
652654

653655
ulong stakes[] = {10000, 10000, 10000, 10000, 10000};
654-
fd_epoch_t * epoch = mock_epoch(wksp, voter_cnt, stakes, voters);
656+
fd_epoch_t * epoch = mock_epoch( wksp, voter_cnt, stakes, voters );
655657

656658
/**********************************************************************/
657659
/* Setup funk_txns for each slot with vote account funk records */
@@ -772,7 +774,7 @@ test_vote_threshold_check( fd_wksp_t * wksp ) {
772774
init_vote_accounts( voters, voter_cnt );
773775

774776
ulong stakes[] = {10000, 10000, 10000, 10000, 10000};
775-
fd_epoch_t * epoch = mock_epoch(wksp, voter_cnt, stakes, voters);
777+
fd_epoch_t * epoch = mock_epoch( wksp, voter_cnt, stakes, voters );
776778

777779
/**********************************************************************/
778780
/* Initialize a funk_txn for each slot with vote account funk records */
@@ -908,7 +910,8 @@ test_full_tower( fd_wksp_t * wksp ) {
908910
void * ghost_mem = fd_wksp_alloc_laddr( wksp, fd_ghost_align(), fd_ghost_footprint( FD_BLOCK_MAX ), 1UL );
909911
fd_ghost_t * ghost = fd_ghost_join( fd_ghost_new( ghost_mem, 0UL, FD_BLOCK_MAX ) );
910912

911-
ghost_init( ghost, 331233273, funk );
913+
ghost_init( ghost, 331233272, funk );
914+
ghost_insert( ghost, 331233272, 331233273, funk );
912915
ghost_insert( ghost, 331233273, 331233274, funk );
913916
ghost_insert( ghost, 331233274, 331233275, funk );
914917
ghost_insert( ghost, 331233275, 331233276, funk );
@@ -972,103 +975,68 @@ test_full_tower( fd_wksp_t * wksp ) {
972975
init_vote_accounts( voters, voter_cnt );
973976

974977
ulong stakes[] = {12, 27, 16, 7, 38};
975-
fd_epoch_t * epoch = mock_epoch(wksp, voter_cnt, stakes, voters);
978+
fd_epoch_t * epoch = mock_epoch( wksp, voter_cnt, stakes, voters );
976979

977-
fd_ghost_print( ghost, epoch, fd_ghost_root(ghost) );
978980
/**********************************************************************/
979981
/* Setup funk_txns for each slot with vote account funk records */
980982
/**********************************************************************/
981983
void * tower_mems[voter_cnt];
984+
fd_tower_t * towers[voter_cnt];
982985
for(ulong i = 0; i < voter_cnt; i++) {
983986
tower_mems[i] = fd_wksp_alloc_laddr( wksp, fd_tower_align(), fd_tower_footprint(), 6UL );
987+
towers[i] = TOWER( tower_mems[i], 331233272, 331233273, 331233274,
988+
331233275, 331233276, 331233277, 331233278,
989+
331233279, 331233280, 331233281, 331233282,
990+
331233283, 331233284, 331233285, 331233286,
991+
331233287, 331233288, 331233289, 331233290,
992+
331233291, 331233292, 331233293, 331233294,
993+
331233295, 331233296, 331233297, 331233298,
994+
331233299, 331233300, 331233301, 331233302);
984995
}
985-
fd_tower_t * towers[] = {
986-
TOWER( tower_mems[0], 331233273, 331233274, 331233275, 331233276,
987-
331233277, 331233278, 331233279, 331233280, 331233281,
988-
331233282, 331233283, 331233284, 331233285, 331233286,
989-
331233287, 331233288, 331233289, 331233290, 331233291,
990-
331233292, 331233293, 331233294, 331233295, 331233296,
991-
331233297, 331233298, 331233299, 331233300, 331233301,
992-
331233302, 331233303),
993-
TOWER( tower_mems[1], 331233273, 331233274, 331233275, 331233276,
994-
331233277, 331233278, 331233279, 331233280, 331233281,
995-
331233282, 331233283, 331233284, 331233285, 331233286,
996-
331233287, 331233288, 331233289, 331233290, 331233291,
997-
331233292, 331233293, 331233294, 331233295, 331233296,
998-
331233297, 331233298, 331233299, 331233300, 331233301,
999-
331233302, 331233303),
1000-
TOWER( tower_mems[2], 331233273, 331233274, 331233275, 331233276,
1001-
331233277, 331233278, 331233279, 331233280, 331233281,
1002-
331233282, 331233283, 331233284, 331233285, 331233286,
1003-
331233287, 331233288, 331233289, 331233290, 331233291,
1004-
331233292, 331233293, 331233294, 331233295, 331233296,
1005-
331233297, 331233298, 331233299, 331233300, 331233301,
1006-
331233302, 331233303),
1007-
TOWER( tower_mems[3], 331233273, 331233274, 331233275, 331233276,
1008-
331233277, 331233278, 331233279, 331233280, 331233281,
1009-
331233282, 331233283, 331233284, 331233285, 331233286,
1010-
331233287, 331233288, 331233289, 331233290, 331233291,
1011-
331233292, 331233293, 331233294, 331233295, 331233296,
1012-
331233297, 331233298, 331233299, 331233300, 331233301,
1013-
331233302, 331233303),
1014-
TOWER( tower_mems[4], 331233273, 331233274, 331233275, 331233276,
1015-
331233277, 331233278, 331233279, 331233280, 331233281,
1016-
331233282, 331233283, 331233284, 331233285, 331233286,
1017-
331233287, 331233288, 331233289, 331233290, 331233291,
1018-
331233292, 331233293, 331233294, 331233295, 331233296,
1019-
331233297, 331233298, 331233299, 331233300, 331233301,
1020-
331233302, 331233303)
1021-
};
1022996

1023997
/**********************************************************************/
1024998
/* Initialize landed votes per validator in funk */
1025999
/**********************************************************************/
1026-
voter_vote_for_slot( wksp, towers[0], funk, 331233302, 331233303, &voters[0] );
1027-
voter_vote_for_slot( wksp, towers[1], funk, 331233302, 331233303, &voters[1] );
1028-
voter_vote_for_slot( wksp, towers[2], funk, 331233302, 331233303, &voters[2] );
1029-
voter_vote_for_slot( wksp, towers[3], funk, 331233302, 331233303, &voters[3] );
1030-
voter_vote_for_slot( wksp, towers[4], funk, 331233302, 331233303, &voters[4] );
1000+
1001+
voter_vote_for_slot( wksp, towers[0], funk, 331233303, 331233304, &voters[0] );
1002+
voter_vote_for_slot( wksp, towers[1], funk, 331233303, 331233304, &voters[1] );
1003+
voter_vote_for_slot( wksp, towers[2], funk, 331233303, 331233304, &voters[2] );
1004+
voter_vote_for_slot( wksp, towers[3], funk, 331233303, 331233304, &voters[3] );
1005+
voter_vote_for_slot( wksp, towers[4], funk, 331233303, 331233304, &voters[4] );
10311006

10321007
/**********************************************************************/
10331008
/* Initialize tower, spad and setup forks */
10341009
/**********************************************************************/
10351010
void * tower_mem = fd_wksp_alloc_laddr( wksp, fd_tower_align(), fd_tower_footprint(), 6UL );
1036-
fd_tower_t * tower = TOWER( tower_mem, 331233273, 331233274, 331233275, 331233276,
1037-
331233277, 331233278, 331233279, 331233280, 331233281,
1038-
331233282, 331233283, 331233284, 331233285, 331233286,
1039-
331233287, 331233288, 331233289, 331233290, 331233291,
1040-
331233292, 331233293, 331233294, 331233295, 331233296,
1041-
331233297, 331233298, 331233299, 331233300, 331233301,
1042-
331233302, 331233303 );
1011+
fd_tower_t * tower = TOWER( tower_mem, 331233272, 331233273, 331233274,
1012+
331233275, 331233276, 331233277, 331233278,
1013+
331233279, 331233280, 331233281, 331233282,
1014+
331233283, 331233284, 331233285, 331233286,
1015+
331233287, 331233288, 331233289, 331233290,
1016+
331233291, 331233292, 331233293, 331233294,
1017+
331233295, 331233296, 331233297, 331233298,
1018+
331233299, 331233300, 331233301, 331233302 );
10431019
FD_TEST( tower );
10441020

10451021
void * spad_mem = fd_wksp_alloc_laddr( wksp, fd_spad_align(), fd_spad_footprint( FD_TOWER_FOOTPRINT ), 5UL );
10461022
fd_spad_t * spad = fd_spad_join( fd_spad_new( spad_mem, FD_TOWER_FOOTPRINT ) );
10471023

10481024
fd_forks_t * forks;
1049-
ulong frontier1 = 331233303UL;
1025+
ulong frontier1 = 331233304UL;
1026+
ulong frontier2 = 331233308UL;
10501027
INIT_FORKS( frontier1 );
1051-
fd_forks_update( forks, epoch, funk, ghost, frontier1 );
1052-
1053-
1054-
fd_funk_txn_xid_t xid;
1055-
xid.ul[0] = xid.ul[1] = 331233304;
1056-
fd_funk_txn_map_query_t query[1];
1057-
fd_funk_txn_map_t txn_map = fd_funk_txn_map( funk, fd_funk_wksp( funk ) );
1058-
fd_funk_txn_map_query_try( &txn_map, &xid, NULL, query, 0 );
1059-
FD_TEST( query->ele );
1028+
ADD_FRONTIER_TO_FORKS( frontier2 );
10601029

1061-
fd_tower_vote( towers[1], 331233304 );
1062-
// fd_landed_vote_t * landed_votes = mock_landed_votes( wksp, 331233304, towers[1], 30 );
1063-
// set_vote_account_tower( wksp, funk, query->ele, &voter[1], landed_votes );
1064-
// VOTE_FOR_SLOT( 331233303UL, 331233304, 0 );
1030+
fd_forks_update( forks, epoch, funk, ghost, frontier1 );
1031+
fd_ghost_print( ghost, epoch, fd_ghost_root(ghost) );
10651032

1033+
voter_vote_for_slot( wksp, towers[1], funk, 331233304, 331233304, &voters[1] );
10661034

1035+
fd_forks_update( forks, epoch, funk, ghost, frontier1 );
1036+
fd_ghost_print( ghost, epoch, fd_ghost_root(ghost) );
10671037

10681038
/* Everyone has voted for slot 331233302 in their towers by slot 331233303 */
10691039
// fd_tower_t * tower = mock_tower( wksp, 31, votes );
1070-
FD_LOG_NOTICE(( "Updated ghost:" ));
1071-
fd_ghost_print( ghost, epoch, fd_ghost_root(ghost) );
10721040

10731041
// ulong root = fd_tower_vote( tower, 331233303 );
10741042
// fd_tower_vote( tower, 331233303 );
@@ -1102,7 +1070,7 @@ main( int argc, char ** argv ) {
11021070
test_vote_lockout_check( wksp );
11031071
test_vote_threshold_check( wksp );
11041072
test_vote_switch_check_4forks( wksp );
1105-
// test_full_tower( wksp );
1073+
test_full_tower( wksp );
11061074
fd_halt();
11071075
return 0;
11081076
}

0 commit comments

Comments
 (0)