@@ -8,22 +8,29 @@ mod legacy_eic_test {
88 use traits :: TryInto ;
99 use option :: OptionTrait ;
1010 use serde :: Serde ;
11- use src :: token_bridge_interface :: {ITokenBridgeDispatcher , ITokenBridgeDispatcherTrait };
12-
1311 use starknet :: class_hash :: {ClassHash , class_hash_const};
1412 use starknet :: {ContractAddress , EthAddress , EthAddressZeroable , syscalls :: deploy_syscall};
15- use src :: legacy_bridge_tester :: LegacyBridgeTester ;
13+ use openzeppelin :: token :: erc20 :: presets :: erc20votes :: ERC20VotesPreset :: {
14+ DAPP_NAME , DAPP_VERSION
15+ };
16+
1617 use src :: legacy_bridge_eic :: LegacyBridgeUpgradeEIC ;
18+ use src :: legacy_bridge_tester :: LegacyBridgeTester ;
19+ use src :: replaceability_interface :: {
20+ EICData , ImplementationData , IReplaceable , IReplaceableDispatcher ,
21+ IReplaceableDispatcherTrait
22+ };
1723 use src :: roles_init_eic :: RolesExternalInitializer ;
1824 use src :: roles_interface :: {IRolesDispatcher , IRolesDispatcherTrait };
19- use src :: token_bridge :: TokenBridge ;
2025 use src :: test_utils :: test_utils :: {
2126 caller, get_roles, get_token_bridge, set_contract_address_as_caller, get_replaceable,
22- DEFAULT_UPGRADE_DELAY
27+ simple_deploy_l2_token, DEFAULT_UPGRADE_DELAY
2328 };
24- use src :: replaceability_interface :: {
25- EICData , ImplementationData , IReplaceable , IReplaceableDispatcher ,
26- IReplaceableDispatcherTrait
29+ use src :: token_bridge_interface :: {ITokenBridgeDispatcher , ITokenBridgeDispatcherTrait };
30+ use src :: token_bridge :: TokenBridge ;
31+ use src :: update_712_vars_eic :: Update712VarsEIC ;
32+ use src :: update712_eic_tester :: {
33+ Update712EICTester , ITester , ITesterDispatcher , ITesterDispatcherTrait
2734 };
2835
2936 fn L1_TOKEN_ADDRESS () -> EthAddress {
@@ -38,6 +45,10 @@ mod legacy_eic_test {
3845 starknet :: contract_address_const :: <2073 >()
3946 }
4047
48+ fn get_712_tester (contract_address : ContractAddress ) -> ITesterDispatcher {
49+ ITesterDispatcher { contract_address }
50+ }
51+
4152 fn deploy_legacy_tester (l2_token : ContractAddress ) -> ContractAddress {
4253 let mut calldata = ArrayTrait :: new ();
4354 l2_token . serialize (ref calldata );
@@ -53,6 +64,17 @@ mod legacy_eic_test {
5364 tester
5465 }
5566
67+ fn deploy_eip_712_tester () -> ContractAddress {
68+ let mut calldata = array! [];
69+ // Set the caller address for all the functions calls (except the constructor).
70+ set_contract_address_as_caller ();
71+
72+ // Deploy the contract.
73+ let (tester , _ ) = deploy_syscall (update_712_eic_tester_hash (), 0 , calldata . span (), false )
74+ . unwrap ();
75+ tester
76+ }
77+
5678 #[test]
5779 #[available_gas(30000000)]
5880 fn test_deploy_tester () {
@@ -68,12 +90,31 @@ mod legacy_eic_test {
6890 LegacyBridgeTester :: TEST_CLASS_HASH . try_into (). unwrap ()
6991 }
7092
93+ fn update_712_eic_tester_hash () -> ClassHash {
94+ Update712EICTester :: TEST_CLASS_HASH . try_into (). unwrap ()
95+ }
96+
97+ fn update_712_eic_hash () -> ClassHash {
98+ Update712VarsEIC :: TEST_CLASS_HASH . try_into (). unwrap ()
99+ }
100+
101+ fn roles_init_eic_hash () -> ClassHash {
102+ RolesExternalInitializer :: TEST_CLASS_HASH . try_into (). unwrap ()
103+ }
104+
105+ fn custom_712_eic_implementation_data (impl_hash : ClassHash ) -> ImplementationData {
106+ generic_eic_implementation_data (: impl_hash , eic_hash : update_712_eic_hash ())
107+ }
108+
71109 fn custom_roles_eic_implementation_data (impl_hash : ClassHash ) -> ImplementationData {
110+ generic_eic_implementation_data (: impl_hash , eic_hash : roles_init_eic_hash ())
111+ }
112+
113+ fn generic_eic_implementation_data (
114+ impl_hash : ClassHash , eic_hash : ClassHash
115+ ) -> ImplementationData {
72116 let mut calldata = array! [];
73- let eic_data = EICData {
74- eic_hash : RolesExternalInitializer :: TEST_CLASS_HASH . try_into (). unwrap (),
75- eic_init_data : calldata . span ()
76- };
117+ let eic_data = EICData { eic_hash , eic_init_data : calldata . span () };
77118
78119 ImplementationData { impl_hash , eic_data : Option :: Some (eic_data ), final : false }
79120 }
@@ -140,19 +181,20 @@ mod legacy_eic_test {
140181 #[test]
141182 #[available_gas(30000000)]
142183 fn test_happy_path () {
143- let tester_address = deploy_legacy_tester (L2_TOKEN_ADDRESS ());
184+ let l2_token = simple_deploy_l2_token ();
185+ let tester_address = deploy_legacy_tester (l2_token );
144186 let impl_data = token_bridge_w_eic_implementation_data (
145- l1_token : L1_TOKEN_ADDRESS (), l2_token : L2_TOKEN_ADDRESS () ,
187+ l1_token : L1_TOKEN_ADDRESS (), : l2_token ,
146188 );
147189 add_impl_and_replace_to (
148190 replaceable_address : tester_address , implementation_data : impl_data ,
149191 );
150192
151193 let token_bridge = get_token_bridge (tester_address );
152- let l1_token = token_bridge . get_l1_token (L2_TOKEN_ADDRESS () );
153- let l2_token = token_bridge . get_l2_token (L1_TOKEN_ADDRESS ());
194+ let l1_token = token_bridge . get_l1_token (l2_token );
195+ let l2_token_actual = token_bridge . get_l2_token (L1_TOKEN_ADDRESS ());
154196 assert (L1_TOKEN_ADDRESS () == l1_token , ' L1_ZEROED' );
155- assert (L2_TOKEN_ADDRESS () == l2_token , ' L2_ZEROED' );
197+ assert (l2_token == l2_token_actual , ' L2_ZEROED' );
156198 }
157199
158200 #[test]
@@ -166,6 +208,8 @@ mod legacy_eic_test {
166208 // Tester 1 roles are not initialzied, and gov admin not set.
167209 let roles1 = get_roles (tester1 );
168210 assert (! roles1 . is_governance_admin (caller ()), ' Roles should not be initialized' );
211+ assert (! roles1 . is_upgrade_governor (caller ()), ' Roles should not be initialized' );
212+ assert (! roles1 . is_security_admin (caller ()), ' Roles should not be initialized' );
169213
170214 // Tester 2 is upgraded to the token_bridge with the roles EIC.
171215 let tester2 = deploy_legacy_tester (ContractAddressZeroable :: zero ());
@@ -175,6 +219,32 @@ mod legacy_eic_test {
175219 // Tester 2 roles are initialized and gov admin assigned.
176220 let roles = get_roles (tester2 );
177221 assert (roles . is_governance_admin (caller ()), ' Roles should be initialized' );
222+ assert (roles . is_upgrade_governor (caller ()), ' Roles should be initialized' );
223+ assert (roles . is_security_admin (caller ()), ' Roles should be initialized' );
224+ }
225+
226+ #[test]
227+ #[available_gas(30000000)]
228+ fn test_update_eip712_vars_eic () {
229+ // Test update_eip712_eic - i.e. that the eic populate vars correctly.
230+
231+ // Deploy tester & check that vars are empty.
232+ let tester_address = deploy_eip_712_tester ();
233+ let tester = get_712_tester (tester_address );
234+ assert (tester . get_dapp_name () == '' , ' dapp_name not empty' );
235+ assert (tester . get_dapp_version () == '' , ' dapp_version not empty' );
236+
237+ // Perform an update with the update_712_eic.
238+ let implementation_data = custom_712_eic_implementation_data (update_712_eic_tester_hash ());
239+ add_impl_and_replace_to (replaceable_address : tester_address , : implementation_data );
240+
241+ // Check that variables are now with correct values.
242+ assert (tester . get_dapp_name () == DAPP_NAME , ' Bad dapp_name' );
243+ assert (tester . get_dapp_version () == DAPP_VERSION , ' Bad dapp_version' );
244+
245+ // Sanity - assert that the values are what we really expect.
246+ assert (DAPP_NAME == ' TOKEN_DELEGATION' , ' Broken test' );
247+ assert (DAPP_VERSION == ' 1.0.0' , ' Broken test' );
178248 }
179249
180250 #[test]
@@ -252,9 +322,10 @@ mod legacy_eic_test {
252322 #[available_gas(30000000)]
253323 fn test_upgrade_an_upgraded () {
254324 // Test failing to upgrade twice.
255- let tester_address = deploy_legacy_tester (L2_TOKEN_ADDRESS ());
325+ let l2_token = simple_deploy_l2_token ();
326+ let tester_address = deploy_legacy_tester (l2_token );
256327 let impl_data = token_bridge_w_eic_implementation_data (
257- l1_token : L1_TOKEN_ADDRESS (), l2_token : L2_TOKEN_ADDRESS () ,
328+ l1_token : L1_TOKEN_ADDRESS (), : l2_token ,
258329 );
259330
260331 // Upgrade first time. All goes well.
0 commit comments