@@ -104,16 +104,17 @@ fn get_extension_indices<V: Extension>(
104
104
let extension_type =
105
105
ExtensionType :: try_from ( & tlv_data[ tlv_indices. type_start ..tlv_indices. length_start ] ) ?;
106
106
let account_type = extension_type. get_account_type ( ) ;
107
- // got to an empty spot, can init here, or move forward if not initing
108
- if extension_type == ExtensionType :: Uninitialized {
107
+ if extension_type == V :: TYPE {
108
+ // found an instance of the extension that we're initializing, return!
109
+ return Ok ( tlv_indices) ;
110
+ // got to an empty spot, init here, or error if we're searching, since
111
+ // nothing is written after an Uninitialized spot
112
+ } else if extension_type == ExtensionType :: Uninitialized {
109
113
if init {
110
114
return Ok ( tlv_indices) ;
111
115
} else {
112
- start_index = tlv_indices . length_start ;
116
+ return Err ( TokenError :: ExtensionNotFound . into ( ) ) ;
113
117
}
114
- } else if extension_type == V :: TYPE {
115
- // found an instance of the extension that we're initializing, return!
116
- return Ok ( tlv_indices) ;
117
118
} else if v_account_type != account_type {
118
119
return Err ( TokenError :: ExtensionTypeMismatch . into ( ) ) ;
119
120
} else {
@@ -1603,8 +1604,14 @@ mod test {
1603
1604
state. base = TEST_ACCOUNT ;
1604
1605
state. pack_base ( ) ;
1605
1606
state. init_account_type ( ) . unwrap ( ) ;
1606
- state. init_extension :: < ImmutableOwner > ( true ) . unwrap ( ) ;
1607
1607
1608
+ let err = state. get_extension :: < ImmutableOwner > ( ) . unwrap_err ( ) ;
1609
+ assert_eq ! (
1610
+ err,
1611
+ ProgramError :: Custom ( TokenError :: ExtensionNotFound as u32 )
1612
+ ) ;
1613
+
1614
+ state. init_extension :: < ImmutableOwner > ( true ) . unwrap ( ) ;
1608
1615
assert_eq ! (
1609
1616
get_first_extension_type( state. tlv_data) . unwrap( ) ,
1610
1617
Some ( ExtensionType :: ImmutableOwner )
0 commit comments