@@ -803,7 +803,7 @@ describe('Contract', function () {
803
803
} )
804
804
it ( 'Valid' , async ( ) => {
805
805
const { decodedResult } = await contractObject . methods . tupleFn ( [ 'test' , 1 ] )
806
- JSON . stringify ( decodedResult ) . should . be . equal ( JSON . stringify ( [ 'test' , 1 ] ) )
806
+ decodedResult . should . be . eql ( [ 'test' , 1 ] )
807
807
} )
808
808
} )
809
809
describe ( 'LIST' , function ( ) {
@@ -830,88 +830,57 @@ describe('Contract', function () {
830
830
} )
831
831
it ( 'Valid' , async ( ) => {
832
832
const { decodedResult } = await contractObject . methods . listInListFn ( [ [ 1 , 2 ] , [ 3 , 4 ] ] )
833
- JSON . stringify ( decodedResult ) . should . be . equal ( JSON . stringify ( [ [ 1 , 2 ] , [ 3 , 4 ] ] ) )
833
+ decodedResult . should . be . eql ( [ [ 1 , 2 ] , [ 3 , 4 ] ] )
834
834
} )
835
835
} )
836
+
836
837
describe ( 'MAP' , function ( ) {
838
+ const address = 'ak_gvxNbZf5CuxYVfcUFoKAP4geZatWaC2Yy4jpx5vZoCKank4Gc'
839
+
837
840
it ( 'Valid' , async ( ) => {
838
- const address = await contract . address ( )
839
- const mapArg = new Map (
840
- [
841
- [ address , [ 'someStringV' , 324 ] ]
842
- ]
843
- )
844
- const objectFromMap = Array . from ( mapArg . entries ( ) ) . reduce ( ( acc , [ k , v ] ) => ( { ...acc , [ k ] : v } ) , { } )
845
- const { decodedResult } = await contractObject . methods . mapFn ( objectFromMap )
846
- JSON . stringify ( decodedResult ) . should . be . equal ( JSON . stringify ( Array . from ( mapArg . entries ( ) ) ) )
841
+ const mapArg = new Map ( [ [ address , [ 'someStringV' , 324 ] ] ] )
842
+ const { decodedResult } = await contractObject . methods . mapFn ( Object . fromEntries ( mapArg ) )
843
+ decodedResult . should . be . eql ( Array . from ( mapArg . entries ( ) ) )
847
844
} )
845
+
848
846
it ( 'Map With Option Value' , async ( ) => {
849
- const address = await contract . address ( )
850
- const mapArgWithSomeValue = new Map (
851
- [
852
- [ address , [ 'someStringV' , 123 ] ]
853
- ]
854
- )
855
- const mapArgWithNoneValue = new Map (
856
- [
857
- [ address , [ 'someStringV' , undefined ] ]
858
- ]
859
- )
860
- const returnArgWithSomeValue = new Map (
861
- [
862
- [ address , [ 'someStringV' , 123 ] ]
863
- ]
864
- )
865
- const returnArgWithNoneValue = new Map (
866
- [
867
- [ address , [ 'someStringV' , undefined ] ]
868
- ]
869
- )
870
- const resultWithSome = await contractObject . methods . mapOptionFn ( mapArgWithSomeValue )
871
- const resultWithNone = await contractObject . methods . mapOptionFn ( mapArgWithNoneValue )
872
-
873
- const decodedSome = resultWithSome . decodedResult
874
-
875
- JSON . stringify ( decodedSome ) . should . be . equal ( JSON . stringify ( Array . from ( returnArgWithSomeValue . entries ( ) ) ) )
876
- JSON . stringify ( resultWithNone . decodedResult ) . should . be . equal ( JSON . stringify ( Array . from ( returnArgWithNoneValue . entries ( ) ) ) )
847
+ const mapWithSomeValue = new Map ( [ [ address , [ 'someStringV' , 123 ] ] ] )
848
+ const mapWithNoneValue = new Map ( [ [ address , [ 'someStringV' , undefined ] ] ] )
849
+ let result = await contractObject . methods . mapOptionFn ( mapWithSomeValue )
850
+ result . decodedResult . should . be . eql ( Array . from ( mapWithSomeValue . entries ( ) ) )
851
+ result = await contractObject . methods . mapOptionFn ( mapWithNoneValue )
852
+ result . decodedResult . should . be . eql ( Array . from ( mapWithNoneValue . entries ( ) ) )
877
853
} )
854
+
878
855
it ( 'Cast from string to int' , async ( ) => {
879
- const address = await contract . address ( )
880
- const mapArg = new Map (
881
- [
882
- [ address , [ 'someStringV' , '324' ] ]
883
- ]
884
- )
856
+ const mapArg = new Map ( [ [ address , [ 'someStringV' , '324' ] ] ] )
885
857
const result = await contractObject . methods . mapFn ( mapArg )
886
858
mapArg . set ( address , [ 'someStringV' , 324 ] )
887
- JSON . stringify ( result . decodedResult ) . should . be . equal ( JSON . stringify ( Array . from ( mapArg . entries ( ) ) ) )
859
+ result . decodedResult . should . be . eql ( Array . from ( mapArg . entries ( ) ) )
888
860
} )
861
+
889
862
it ( 'Cast from array to map' , async ( ) => {
890
- const address = await contract . address ( )
891
- const mapArg =
892
- [
893
- [ address , [ 'someStringV' , 324 ] ]
894
- ]
863
+ const mapArg = [ [ address , [ 'someStringV' , 324 ] ] ]
895
864
const { decodedResult } = await contractObject . methods . mapFn ( mapArg )
896
- JSON . stringify ( decodedResult ) . should . be . equal ( JSON . stringify ( mapArg ) )
865
+ decodedResult . should . be . eql ( mapArg )
897
866
} )
898
867
} )
868
+
899
869
describe ( 'RECORD/STATE' , function ( ) {
900
- const objEq = ( obj , obj2 ) => ! Object . entries ( obj ) . find ( ( [ key , val ] ) => JSON . stringify ( obj2 [ key ] ) !== JSON . stringify ( val ) )
901
870
it ( 'Valid Set Record (Cast from JS object)' , async ( ) => {
902
871
await contractObject . methods . setRecord ( { value : 'qwe' , key : 1234 , testOption : 'test' } )
903
872
const state = await contractObject . methods . getRecord ( )
904
873
905
- objEq ( state . decodedResult , { value : 'qwe' , key : 1234 , testOption : 'test' } ) . should . be . equal ( true )
874
+ state . decodedResult . should . be . eql ( { value : 'qwe' , key : 1234 , testOption : 'test' } )
906
875
} )
907
876
it ( 'Get Record(Convert to JS object)' , async ( ) => {
908
877
const result = await contractObject . methods . getRecord ( )
909
- objEq ( result . decodedResult , { value : 'qwe' , key : 1234 , testOption : 'test' } ) . should . be . equal ( true )
878
+ result . decodedResult . should . be . eql ( { value : 'qwe' , key : 1234 , testOption : 'test' } )
910
879
} )
911
880
it ( 'Get Record With Option (Convert to JS object)' , async ( ) => {
912
881
await contractObject . methods . setRecord ( { key : 1234 , value : 'qwe' , testOption : 'resolved string' } )
913
882
const result = await contractObject . methods . getRecord ( )
914
- objEq ( result . decodedResult , { value : 'qwe' , key : 1234 , testOption : 'resolved string' } ) . should . be . equal ( true )
883
+ result . decodedResult . should . be . eql ( { value : 'qwe' , key : 1234 , testOption : 'resolved string' } )
915
884
} )
916
885
it ( 'Invalid value type' , async ( ) => {
917
886
try {
@@ -930,7 +899,7 @@ describe('Contract', function () {
930
899
it ( 'Set Some Option List Value(Cast from JS value/Convert result to JS)' , async ( ) => {
931
900
const optionRes = await contractObject . methods . listOption ( [ [ 1 , 'testString' ] ] )
932
901
933
- JSON . stringify ( optionRes . decodedResult ) . should . be . equal ( JSON . stringify ( [ [ 1 , 'testString' ] ] ) )
902
+ optionRes . decodedResult . should . be . eql ( [ [ 1 , 'testString' ] ] )
934
903
} )
935
904
it ( 'Set None Option Value(Cast from JS value/Convert to JS)' , async ( ) => {
936
905
const optionRes = await contractObject . methods . intOption ( undefined )
@@ -980,7 +949,7 @@ describe('Contract', function () {
980
949
} )
981
950
it ( 'Valid' , async ( ) => {
982
951
const res = await contractObject . methods . datTypeFn ( 'Year' )
983
- JSON . stringify ( res . decodedResult ) . should . be . equal ( '" Year" ' )
952
+ res . decodedResult . should . be . equal ( 'Year' )
984
953
} )
985
954
} )
986
955
describe ( 'Hash' , function ( ) {
@@ -1078,9 +1047,8 @@ describe('Contract', function () {
1078
1047
contractObject . setOptions ( { skipTransformDecoded : true } )
1079
1048
const res = await contractObject . methods . listFn ( [ 1 , 2 ] )
1080
1049
const decoded = await res . decode ( )
1081
- const decodedJSON = JSON . stringify ( [ 1 , 2 ] )
1082
1050
contractObject . setOptions ( { skipTransformDecoded : false } )
1083
- JSON . stringify ( decoded ) . should . be . equal ( decodedJSON )
1051
+ decoded . should . be . eql ( [ 1 , 2 ] )
1084
1052
} )
1085
1053
it ( 'Call contract with contract type argument' , async ( ) => {
1086
1054
const result = await contractObject . methods . approve ( 0 , 'ct_AUUhhVZ9de4SbeRk8ekos4vZJwMJohwW5X8KQjBMUVduUmoUh' )
0 commit comments