|
1 | 1 | using System.Numerics; |
| 2 | +using Newtonsoft.Json.Linq; |
2 | 3 |
|
3 | 4 | namespace Thirdweb.Tests.Utilities; |
4 | 5 |
|
@@ -763,4 +764,104 @@ public async Task FetchGasFees_Celo() |
763 | 764 | Assert.True(maxPrio > 0); |
764 | 765 | Assert.Equal(maxFee, maxPrio); |
765 | 766 | } |
| 767 | + |
| 768 | + [Fact] |
| 769 | + public void PreprocessTypedDataJson_FormatsBigIntegers() |
| 770 | + { |
| 771 | + // Arrange |
| 772 | + var inputJson = |
| 773 | + /*lang=json,strict*/ |
| 774 | + @" |
| 775 | + { |
| 776 | + ""from"": 973250616940336452028326648501327235277017847475, |
| 777 | + ""data"": ""0x"", |
| 778 | + ""nested"": { |
| 779 | + ""value"": 4294967295 |
| 780 | + }, |
| 781 | + ""array"": [ |
| 782 | + 123, |
| 783 | + 973250616940336452028326648501327235277017847475 |
| 784 | + ] |
| 785 | + }"; |
| 786 | + |
| 787 | + var expectedJson = |
| 788 | + /*lang=json,strict*/ |
| 789 | + @" |
| 790 | + { |
| 791 | + ""from"": ""973250616940336452028326648501327235277017847475"", |
| 792 | + ""data"": ""0x"", |
| 793 | + ""nested"": { |
| 794 | + ""value"": 4294967295 |
| 795 | + }, |
| 796 | + ""array"": [ |
| 797 | + 123, |
| 798 | + ""973250616940336452028326648501327235277017847475"" |
| 799 | + ] |
| 800 | + }"; |
| 801 | + |
| 802 | + // Act |
| 803 | + var processedJson = Utils.PreprocessTypedDataJson(inputJson); |
| 804 | + |
| 805 | + // Assert |
| 806 | + var expectedJObject = JObject.Parse(expectedJson); |
| 807 | + var processedJObject = JObject.Parse(processedJson); |
| 808 | + |
| 809 | + Assert.Equal(expectedJObject, processedJObject); |
| 810 | + } |
| 811 | + |
| 812 | + [Fact] |
| 813 | + public void PreprocessTypedDataJson_NoLargeNumbers_NoChange() |
| 814 | + { |
| 815 | + // Arrange |
| 816 | + var inputJson = |
| 817 | + /*lang=json,strict*/ |
| 818 | + @" |
| 819 | + { |
| 820 | + ""value"": 123, |
| 821 | + ""nested"": { |
| 822 | + ""value"": 456 |
| 823 | + }, |
| 824 | + ""array"": [1, 2, 3] |
| 825 | + }"; |
| 826 | + |
| 827 | + // Act |
| 828 | + var processedJson = Utils.PreprocessTypedDataJson(inputJson); |
| 829 | + |
| 830 | + // Assert |
| 831 | + Assert.Equal(inputJson.Replace("\r\n", "").Replace(" ", ""), processedJson.Replace("\r\n", "").Replace(" ", "")); |
| 832 | + } |
| 833 | + |
| 834 | + [Fact] |
| 835 | + public void PreprocessTypedDataJson_NestedLargeNumbers() |
| 836 | + { |
| 837 | + // Arrange |
| 838 | + var inputJson = |
| 839 | + /*lang=json,strict*/ |
| 840 | + @" |
| 841 | + { |
| 842 | + ""nested"": { |
| 843 | + ""value"": 973250616940336452028326648501327235277017847475 |
| 844 | + }, |
| 845 | + ""array"": [123, 973250616940336452028326648501327235277017847475] |
| 846 | + }"; |
| 847 | + |
| 848 | + var expectedJson = |
| 849 | + /*lang=json,strict*/ |
| 850 | + @" |
| 851 | + { |
| 852 | + ""nested"": { |
| 853 | + ""value"": ""973250616940336452028326648501327235277017847475"" |
| 854 | + }, |
| 855 | + ""array"": [123, ""973250616940336452028326648501327235277017847475""] |
| 856 | + }"; |
| 857 | + |
| 858 | + // Act |
| 859 | + var processedJson = Utils.PreprocessTypedDataJson(inputJson); |
| 860 | + |
| 861 | + // Assert |
| 862 | + var expectedJObject = JObject.Parse(expectedJson); |
| 863 | + var processedJObject = JObject.Parse(processedJson); |
| 864 | + |
| 865 | + Assert.Equal(expectedJObject, processedJObject); |
| 866 | + } |
766 | 867 | } |
0 commit comments