@@ -1990,4 +1990,234 @@ mod test {
19901990 let unpacked = TokenInstruction :: unpack ( & expect) . unwrap ( ) ;
19911991 assert_eq ! ( unpacked, check) ;
19921992 }
1993+
1994+ macro_rules! test_instruction {
1995+ ( $a: ident( $( $b: tt) * ) ) => {
1996+ let instruction_v3 = spl_token:: instruction:: $a( $( $b) * ) . unwrap( ) ;
1997+ let instruction_2022 = $a( $( $b) * ) . unwrap( ) ;
1998+ assert_eq!( instruction_v3, instruction_2022) ;
1999+ }
2000+ }
2001+
2002+ #[ test]
2003+ fn test_v3_compatibility ( ) {
2004+ let token_program_id = spl_token:: id ( ) ;
2005+ let mint_pubkey = Pubkey :: new_unique ( ) ;
2006+ let mint_authority_pubkey = Pubkey :: new_unique ( ) ;
2007+ let freeze_authority_pubkey = Pubkey :: new_unique ( ) ;
2008+ let decimals = 9u8 ;
2009+
2010+ let account_pubkey = Pubkey :: new_unique ( ) ;
2011+ let owner_pubkey = Pubkey :: new_unique ( ) ;
2012+
2013+ let multisig_pubkey = Pubkey :: new_unique ( ) ;
2014+ let signer_pubkeys_vec = vec ! [ Pubkey :: new_unique( ) ; MAX_SIGNERS ] ;
2015+ let signer_pubkeys = signer_pubkeys_vec. iter ( ) . collect :: < Vec < _ > > ( ) ;
2016+ let m = 10u8 ;
2017+
2018+ let source_pubkey = Pubkey :: new_unique ( ) ;
2019+ let destination_pubkey = Pubkey :: new_unique ( ) ;
2020+ let authority_pubkey = Pubkey :: new_unique ( ) ;
2021+ let amount = 1_000_000_000_000 ;
2022+
2023+ let delegate_pubkey = Pubkey :: new_unique ( ) ;
2024+ let owned_pubkey = Pubkey :: new_unique ( ) ;
2025+ let new_authority_pubkey = Pubkey :: new_unique ( ) ;
2026+
2027+ let ui_amount = "100000.00" ;
2028+
2029+ test_instruction ! ( initialize_mint(
2030+ & token_program_id,
2031+ & mint_pubkey,
2032+ & mint_authority_pubkey,
2033+ None ,
2034+ decimals,
2035+ ) ) ;
2036+ test_instruction ! ( initialize_mint2(
2037+ & token_program_id,
2038+ & mint_pubkey,
2039+ & mint_authority_pubkey,
2040+ Some ( & freeze_authority_pubkey) ,
2041+ decimals,
2042+ ) ) ;
2043+
2044+ test_instruction ! ( initialize_account(
2045+ & token_program_id,
2046+ & account_pubkey,
2047+ & mint_pubkey,
2048+ & owner_pubkey,
2049+ ) ) ;
2050+ test_instruction ! ( initialize_account2(
2051+ & token_program_id,
2052+ & account_pubkey,
2053+ & mint_pubkey,
2054+ & owner_pubkey,
2055+ ) ) ;
2056+ test_instruction ! ( initialize_account3(
2057+ & token_program_id,
2058+ & account_pubkey,
2059+ & mint_pubkey,
2060+ & owner_pubkey,
2061+ ) ) ;
2062+ test_instruction ! ( initialize_multisig(
2063+ & token_program_id,
2064+ & multisig_pubkey,
2065+ & signer_pubkeys,
2066+ m,
2067+ ) ) ;
2068+ test_instruction ! ( initialize_multisig2(
2069+ & token_program_id,
2070+ & multisig_pubkey,
2071+ & signer_pubkeys,
2072+ m,
2073+ ) ) ;
2074+ #[ allow( deprecated) ]
2075+ {
2076+ test_instruction ! ( transfer(
2077+ & token_program_id,
2078+ & source_pubkey,
2079+ & destination_pubkey,
2080+ & authority_pubkey,
2081+ & signer_pubkeys,
2082+ amount
2083+ ) ) ;
2084+ }
2085+ test_instruction ! ( transfer_checked(
2086+ & token_program_id,
2087+ & source_pubkey,
2088+ & mint_pubkey,
2089+ & destination_pubkey,
2090+ & authority_pubkey,
2091+ & signer_pubkeys,
2092+ amount,
2093+ decimals,
2094+ ) ) ;
2095+ test_instruction ! ( approve(
2096+ & token_program_id,
2097+ & source_pubkey,
2098+ & delegate_pubkey,
2099+ & owner_pubkey,
2100+ & signer_pubkeys,
2101+ amount
2102+ ) ) ;
2103+ test_instruction ! ( approve_checked(
2104+ & token_program_id,
2105+ & source_pubkey,
2106+ & mint_pubkey,
2107+ & delegate_pubkey,
2108+ & owner_pubkey,
2109+ & signer_pubkeys,
2110+ amount,
2111+ decimals
2112+ ) ) ;
2113+ test_instruction ! ( revoke(
2114+ & token_program_id,
2115+ & source_pubkey,
2116+ & owner_pubkey,
2117+ & signer_pubkeys,
2118+ ) ) ;
2119+
2120+ // set_authority
2121+ {
2122+ let instruction_v3 = spl_token:: instruction:: set_authority (
2123+ & token_program_id,
2124+ & owned_pubkey,
2125+ Some ( & new_authority_pubkey) ,
2126+ spl_token:: instruction:: AuthorityType :: AccountOwner ,
2127+ & owner_pubkey,
2128+ & signer_pubkeys,
2129+ )
2130+ . unwrap ( ) ;
2131+ let instruction_2022 = set_authority (
2132+ & token_program_id,
2133+ & owned_pubkey,
2134+ Some ( & new_authority_pubkey) ,
2135+ AuthorityType :: AccountOwner ,
2136+ & owner_pubkey,
2137+ & signer_pubkeys,
2138+ )
2139+ . unwrap ( ) ;
2140+ assert_eq ! ( instruction_v3, instruction_2022) ;
2141+ }
2142+
2143+ test_instruction ! ( mint_to(
2144+ & token_program_id,
2145+ & mint_pubkey,
2146+ & account_pubkey,
2147+ & owner_pubkey,
2148+ & signer_pubkeys,
2149+ amount,
2150+ ) ) ;
2151+ test_instruction ! ( mint_to_checked(
2152+ & token_program_id,
2153+ & mint_pubkey,
2154+ & account_pubkey,
2155+ & owner_pubkey,
2156+ & signer_pubkeys,
2157+ amount,
2158+ decimals,
2159+ ) ) ;
2160+ test_instruction ! ( burn(
2161+ & token_program_id,
2162+ & account_pubkey,
2163+ & mint_pubkey,
2164+ & authority_pubkey,
2165+ & signer_pubkeys,
2166+ amount,
2167+ ) ) ;
2168+ test_instruction ! ( burn_checked(
2169+ & token_program_id,
2170+ & account_pubkey,
2171+ & mint_pubkey,
2172+ & authority_pubkey,
2173+ & signer_pubkeys,
2174+ amount,
2175+ decimals,
2176+ ) ) ;
2177+ test_instruction ! ( close_account(
2178+ & token_program_id,
2179+ & account_pubkey,
2180+ & destination_pubkey,
2181+ & owner_pubkey,
2182+ & signer_pubkeys,
2183+ ) ) ;
2184+ test_instruction ! ( freeze_account(
2185+ & token_program_id,
2186+ & account_pubkey,
2187+ & mint_pubkey,
2188+ & owner_pubkey,
2189+ & signer_pubkeys,
2190+ ) ) ;
2191+ test_instruction ! ( thaw_account(
2192+ & token_program_id,
2193+ & account_pubkey,
2194+ & mint_pubkey,
2195+ & owner_pubkey,
2196+ & signer_pubkeys,
2197+ ) ) ;
2198+ test_instruction ! ( sync_native( & token_program_id, & account_pubkey, ) ) ;
2199+
2200+ // get_account_data_size
2201+ {
2202+ let instruction_v3 =
2203+ spl_token:: instruction:: get_account_data_size ( & token_program_id, & mint_pubkey)
2204+ . unwrap ( ) ;
2205+ let instruction_2022 =
2206+ get_account_data_size ( & token_program_id, & mint_pubkey, & [ ] ) . unwrap ( ) ;
2207+ assert_eq ! ( instruction_v3, instruction_2022) ;
2208+ }
2209+
2210+ test_instruction ! ( initialize_immutable_owner(
2211+ & token_program_id,
2212+ & account_pubkey,
2213+ ) ) ;
2214+
2215+ test_instruction ! ( amount_to_ui_amount( & token_program_id, & mint_pubkey, amount, ) ) ;
2216+
2217+ test_instruction ! ( ui_amount_to_amount(
2218+ & token_program_id,
2219+ & mint_pubkey,
2220+ ui_amount,
2221+ ) ) ;
2222+ }
19932223}
0 commit comments