@@ -47,13 +47,13 @@ pub fn COption(T: type) type {
4747 }
4848 }
4949 pub fn fromValue (value : T ) Self {
50- return Self {
50+ return Self {
5151 .is_some = 1 ,
5252 .value = value ,
5353 };
5454 }
5555 pub fn asNull () Self {
56- return Self {
56+ return Self {
5757 .is_some = 0 ,
5858 .value = std .mem .zeroes (T ),
5959 };
@@ -73,36 +73,35 @@ pub const Multisig = packed struct {
7373};
7474
7575test "Mint: bitCast" {
76- const mint = Mint {
76+ const mint = Mint {
7777 .authority = COption (PublicKey ).fromOptional (std .mem .bytesToValue (PublicKey , &[_ ]u8 {1 } ** 32 )),
7878 .supply = 42 ,
7979 .decimals = 7 ,
8080 .is_initialized = 1 ,
8181 .freeze_authority = COption (PublicKey ).fromOptional (std .mem .bytesToValue (PublicKey , &[_ ]u8 {2 } ** 32 )),
8282 };
8383 const mint_buffer = [_ ]u8 {
84- 1 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
84+ 1 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
8585 1 , 1 , 1 , 1 , 1 , 1 , 42 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 1 , 1 , 0 , 0 , 0 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
86- 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
86+ 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
8787 };
8888 try std .testing .expectEqualSlices (u8 , & mint_buffer , std .mem .asBytes (& mint )[0.. 82]);
8989 const cast_mint : Mint = @bitCast (mint_buffer );
9090 try std .testing .expectEqual (cast_mint , mint );
9191}
9292
9393test "Mint: cast with padding" {
94- const mint = Mint {
94+ const mint = Mint {
9595 .authority = COption (PublicKey ).new (std .mem .bytesToValue (PublicKey , &[_ ]u8 {1 } ** 32 )),
9696 .supply = 42 ,
9797 .decimals = 7 ,
9898 .is_initialized = 1 ,
9999 .freeze_authority = COption (PublicKey ).new (std .mem .bytesToValue (PublicKey , &[_ ]u8 {2 } ** 32 )),
100100 };
101101 const mint_buffer = [_ ]u8 {
102- 0 ,
103- 1 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
104- 1 , 1 , 1 , 1 , 1 , 1 , 42 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 1 , 1 , 0 , 0 , 0 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
105- 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
102+ 0 , 1 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
103+ 1 , 1 , 1 , 1 , 1 , 1 , 42 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 1 , 1 , 0 , 0 , 0 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
104+ 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
106105 };
107106 try std .testing .expectEqualSlices (u8 , mint_buffer [1.. ], std .mem .asBytes (& mint )[0.. 82]);
108107 const cast_mint : * const Mint = @alignCast (@ptrCast (mint_buffer [1.. ]));
0 commit comments