|
1 | 1 | import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:reown_core/models/tvf_data.dart'; |
2 | 3 | import 'package:reown_core/reown_core.dart'; |
3 | 4 | import 'package:reown_core/store/generic_store.dart'; |
4 | 5 | import 'package:reown_sign/reown_sign.dart'; |
@@ -1103,5 +1104,137 @@ void main() { |
1103 | 1104 | expect(hashes, isNull); |
1104 | 1105 | }); |
1105 | 1106 | }); |
| 1107 | + |
| 1108 | + group('Direct Method Testing - collectHashes - Stellar', () { |
| 1109 | + // Stellar test vectors are real transactions fetched from Horizon |
| 1110 | + // (expected hash == the `hash` field of `GET /transactions/{hash}`). |
| 1111 | + const pubnetV1Xdr = |
| 1112 | + 'AAAAAgAAAACutgsH0wwp9iT1V1zWE8jbQAm7JNeTEx4zdvWD4Jtk8wAAAGQDymekAAAAHAAAAAEAAAAAAAAAAAAAAABqguWuAAAAAAAAAAEAAAAAAAAAAQAAAACutgsH0wwp9iT1V1zWE8jbQAm7JNeTEx4zdvWD4Jtk8wAAAAAAAAAAAJiWgAAAAAAAAAAB4Jtk8wAAAECrfMK7BzVXCay0QnEItO7dJ8Ix2wGaMnFfbWHW1tE6cezMinDXiDtlVBwoK2GjAbrE0h+eGDjDqWWaRS1XDrwE'; |
| 1113 | + const pubnetV1Hash = |
| 1114 | + '628ef4f404cba337f757a640260984830728c92101af0a051fb59fc8c79521c6'; |
| 1115 | + |
| 1116 | + const pubnetFeeBumpXdr = |
| 1117 | + 'AAAABQAAAAA0mMHF8QGzwsMRBhe9i8PSIqxjNjKyQMyXZODBAdhAUwAAAAAAA5+BAAAAAgAAAAA6Hd6p+AA5GTO2bJqKN/hbBfWcOh2Ow8cnTY3iIFFVPAADnrgDoCvmAAAZVgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAADod3qn4ADkZM7Zsmoo3+FsF9Zw6HY7DxydNjeIgUVU8AAAAGAAAAAAAAAAB1/5EvQrxHWArEJHy9KH03yEtRE0DIeoyrbPMHLurCgQAAAAEd29yawAAAAMAAAASAAAAAAAAAAA6Hd6p+AA5GTO2bJqKN/hbBfWcOh2Ow8cnTY3iIFFVPAAAAA0AAAAgAAAAjpSFVoEyx/Ev5d2V/desEr+GEqMyXKvrs5wXFqwAAAAFAAAAAAIrSjwAAAAAAAAAAQAAAAAAAAABAAAAB9ssFCkNSWTjgF8lJ90TKTm6X7P8ysVrML+rj9CRARYnAAAAAwAAAAYAAAAB1/5EvQrxHWArEJHy9KH03yEtRE0DIeoyrbPMHLurCgQAAAAQAAAAAQAAAAIAAAAPAAAABUJsb2NrAAAAAAAAAwACsj8AAAAAAAAABgAAAAHX/kS9CvEdYCsQkfL0ofTfIS1ETQMh6jKts8wcu6sKBAAAABAAAAABAAAAAwAAAA8AAAAEUGFpbAAAABIAAAAAAAAAADod3qn4ADkZM7Zsmoo3+FsF9Zw6HY7DxydNjeIgUVU8AAAAAwACsj8AAAAAAAAABgAAAAHX/kS9CvEdYCsQkfL0ofTfIS1ETQMh6jKts8wcu6sKBAAAABQAAAABABvFygAAAAAAAAXIAAAAAAADnrgAAAABIFFVPAAAAEBbcalx54eMMHwWJz7tzgOoxIVmMl4pexbgwTLzxnyMtAhZ2nZlsF18jIMDBaubSNSNPi4YRHkSajpyOcdZOzsCAAAAAAAAAAEB2EBTAAAAQDOlpIeUB73BImAZJCSAt0cuKZXHlKG+TJ+j+fCeFe9bDc5wHzMlDjU6YlB6geCuxRi7QwTq4RgxrOIJ9HICfg8='; |
| 1118 | + const pubnetFeeBumpHash = |
| 1119 | + '5906453d5a367b4a8a1af9bbbc934904841718ec1ca1345874904e15f97bf83b'; |
| 1120 | + |
| 1121 | + const testnetV1Xdr = |
| 1122 | + 'AAAAAgAAAAAJDqKNhO2/XZAvmR1Wynm2lxfIUQwB6TDzqNVOlQgQTgAAm74AJGh0ABKiOwAAAAEAAAAAAAAAAAAAAABqgthtAAAAAAAAAAEAAAAAAAAAGAAAAAAAAAABmtIg9IzJFxPz3yuidCMj3LiE2SB3XYOl8DvtohHRPVAAAAAJc2V0X3ByaWNlAAAAAAAAAwAAABIAAAAAAAAAAAkOoo2E7b9dkC+ZHVbKebaXF8hRDAHpMPOo1U6VCBBOAAAADwAAAAZFVEhVU0QAAAAAAAoAAAAAAAAAAAAAAARomVswAAAAAQAAAAAAAAAAAAAAAZrSIPSMyRcT898ronQjI9y4hNkgd12DpfA77aIR0T1QAAAACXNldF9wcmljZQAAAAAAAAMAAAASAAAAAAAAAAAJDqKNhO2/XZAvmR1Wynm2lxfIUQwB6TDzqNVOlQgQTgAAAA8AAAAGRVRIVVNEAAAAAAAKAAAAAAAAAAAAAAAEaJlbMAAAAAAAAAABAAAAAAAAAAQAAAAGAAAAAcbgeSm1T8h+V5r+/0u+qUVZIopr5hDeGKj1+u37faSgAAAAEAAAAAEAAAADAAAADwAAAAdIYXNSb2xlAAAAABIAAAAAAAAAAAkOoo2E7b9dkC+ZHVbKebaXF8hRDAHpMPOo1U6VCBBOAAAADwAAAAZPUkFDTEUAAAAAAAEAAAAGAAAAAcbgeSm1T8h+V5r+/0u+qUVZIopr5hDeGKj1+u37faSgAAAAFAAAAAEAAAAHve3Sc2JfmD0Hu+w96oFCzEX1XxFR0uE/NeSf2Vqmia8AAAAH4IWMslKp5yCKjCiGPIRV6yV0LdrLOEfRrCRSwjur0G8AAAABAAAABgAAAAGa0iD0jMkXE/PfK6J0IyPcuITZIHddg6XwO+2iEdE9UAAAABQAAAABADikCAAAAAAAAAJUAAAAAAAATa0AAAABlQgQTgAAAEDSMm2vdKNsB2TCk+Pbb6vSYgq6Zd5F0E4H5BfMi4lwWEcYFAq2Mp+e12wr1qU+Ni7+2BTqZUkb+uK7lVM8PqkN'; |
| 1123 | + const testnetV1Hash = |
| 1124 | + 'c9b2d35ab15c055acb422872a8f1680a84ad6b8ad0d56271cfb74c083edf2007'; |
| 1125 | + |
| 1126 | + test('should compute hash for stellar_signXDR on pubnet', () { |
| 1127 | + // Arrange |
| 1128 | + const id = 500; |
| 1129 | + signEngine.pendingTVFRequests[id] = const TVFData( |
| 1130 | + rpcMethods: ['stellar_signXDR'], |
| 1131 | + chainId: 'stellar:pubnet', |
| 1132 | + ); |
| 1133 | + final response = JsonRpcResponse( |
| 1134 | + id: id, |
| 1135 | + result: { |
| 1136 | + 'signedXDR': pubnetV1Xdr, |
| 1137 | + 'signerAddress': |
| 1138 | + 'stellar:pubnet:GCXLMCYH2MGCT5RE6VLVZVQTZDNUACN3ETLZGEY6GN3PLA7ATNSPGGJH', |
| 1139 | + }, |
| 1140 | + ); |
| 1141 | + |
| 1142 | + // Act |
| 1143 | + final hashes = signEngine.collectHashes('stellar', response); |
| 1144 | + |
| 1145 | + // Assert |
| 1146 | + expect(hashes, equals([pubnetV1Hash])); |
| 1147 | + }); |
| 1148 | + |
| 1149 | + test('should default to pubnet for stellar_signXDR without pending request', () { |
| 1150 | + // Arrange |
| 1151 | + final response = JsonRpcResponse( |
| 1152 | + id: 501, |
| 1153 | + result: {'signedXDR': pubnetV1Xdr}, |
| 1154 | + ); |
| 1155 | + |
| 1156 | + // Act |
| 1157 | + final hashes = signEngine.collectHashes('stellar', response); |
| 1158 | + |
| 1159 | + // Assert |
| 1160 | + expect(hashes, equals([pubnetV1Hash])); |
| 1161 | + }); |
| 1162 | + |
| 1163 | + test('should compute canonical fee-bump hash for a fee-bump envelope', () { |
| 1164 | + // Arrange |
| 1165 | + const id = 502; |
| 1166 | + signEngine.pendingTVFRequests[id] = const TVFData( |
| 1167 | + rpcMethods: ['stellar_signXDR'], |
| 1168 | + chainId: 'stellar:pubnet', |
| 1169 | + ); |
| 1170 | + final response = JsonRpcResponse( |
| 1171 | + id: id, |
| 1172 | + result: {'signedXDR': pubnetFeeBumpXdr}, |
| 1173 | + ); |
| 1174 | + |
| 1175 | + // Act |
| 1176 | + final hashes = signEngine.collectHashes('stellar', response); |
| 1177 | + |
| 1178 | + // Assert — H_fb, the hash explorers index, not the inner tx hash |
| 1179 | + expect(hashes, equals([pubnetFeeBumpHash])); |
| 1180 | + }); |
| 1181 | + |
| 1182 | + test('should compute hash for stellar_signXDR on testnet', () { |
| 1183 | + // Arrange |
| 1184 | + const id = 503; |
| 1185 | + signEngine.pendingTVFRequests[id] = const TVFData( |
| 1186 | + rpcMethods: ['stellar_signXDR'], |
| 1187 | + chainId: 'stellar:testnet', |
| 1188 | + ); |
| 1189 | + final response = JsonRpcResponse( |
| 1190 | + id: id, |
| 1191 | + result: {'signedXDR': testnetV1Xdr}, |
| 1192 | + ); |
| 1193 | + |
| 1194 | + // Act |
| 1195 | + final hashes = signEngine.collectHashes('stellar', response); |
| 1196 | + |
| 1197 | + // Assert |
| 1198 | + expect(hashes, equals([testnetV1Hash])); |
| 1199 | + }); |
| 1200 | + |
| 1201 | + test('should extract tx_hash for stellar_signAndSubmitXDR', () { |
| 1202 | + // Arrange |
| 1203 | + final response = JsonRpcResponse( |
| 1204 | + id: 504, |
| 1205 | + result: { |
| 1206 | + 'tx_hash': |
| 1207 | + '6da5298ae2b4fd1567fa3f760e66c9fb9014e3ac72bf48af1ad8120f8423b961', |
| 1208 | + 'signedXDR': 'AAAAAg==', |
| 1209 | + 'successful': true, |
| 1210 | + }, |
| 1211 | + ); |
| 1212 | + |
| 1213 | + // Act |
| 1214 | + final hashes = signEngine.collectHashes('stellar', response); |
| 1215 | + |
| 1216 | + // Assert |
| 1217 | + expect( |
| 1218 | + hashes, |
| 1219 | + equals([ |
| 1220 | + '6da5298ae2b4fd1567fa3f760e66c9fb9014e3ac72bf48af1ad8120f8423b961', |
| 1221 | + ]), |
| 1222 | + ); |
| 1223 | + }); |
| 1224 | + |
| 1225 | + test('should return null for a malformed stellar envelope', () { |
| 1226 | + // Arrange |
| 1227 | + final response = JsonRpcResponse( |
| 1228 | + id: 505, |
| 1229 | + result: {'signedXDR': 'q83vASNFZ4mrze8BI0VniavN7wEjRWeJq83vAQ=='}, |
| 1230 | + ); |
| 1231 | + |
| 1232 | + // Act |
| 1233 | + final hashes = signEngine.collectHashes('stellar', response); |
| 1234 | + |
| 1235 | + // Assert |
| 1236 | + expect(hashes, isNull); |
| 1237 | + }); |
| 1238 | + }); |
1106 | 1239 | }); |
1107 | 1240 | } |
0 commit comments