github.com/status-im/status-go@v1.1.0/services/wallet/thirdparty/rarible/client_test.go (about)

     1  package rarible
     2  
     3  import (
     4  	"encoding/json"
     5  	"math/big"
     6  	"testing"
     7  
     8  	"github.com/ethereum/go-ethereum/common"
     9  	"github.com/status-im/status-go/services/wallet/bigint"
    10  	w_common "github.com/status-im/status-go/services/wallet/common"
    11  	"github.com/status-im/status-go/services/wallet/thirdparty"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestUnmarshallCollection(t *testing.T) {
    17  	expectedCollectionData := thirdparty.CollectionData{
    18  		ID: thirdparty.ContractID{
    19  			ChainID: 1,
    20  			Address: common.HexToAddress("0x06012c8cf97bead5deae237070f9587f8e7a266d"),
    21  		},
    22  		ContractType: w_common.ContractTypeERC721,
    23  		Provider:     "rarible",
    24  		Name:         "CryptoKitties",
    25  		ImageURL:     "https://i.seadn.io/gae/C272ZRW1RGGef9vKMePFSCeKc1Lw6U40wl9ofNVxzUxFdj84hH9xJRQNf-7wgs7W8qw8RWe-1ybKp-VKuU5D-tg?w=500&auto=format",
    26  		Traits:       make(map[string]thirdparty.CollectionTrait),
    27  		Socials:      nil,
    28  	}
    29  
    30  	collection := Collection{}
    31  	err := json.Unmarshal([]byte(collectionJSON), &collection)
    32  	assert.NoError(t, err)
    33  
    34  	contractID, err := raribleContractIDToUniqueID(collection.ID, true)
    35  	assert.NoError(t, err)
    36  
    37  	collectionData := collection.toCommon(contractID)
    38  	assert.Equal(t, expectedCollectionData, collectionData)
    39  }
    40  
    41  func TestUnmarshallOwnedCollectibles(t *testing.T) {
    42  	expectedTokenID0, _ := big.NewInt(0).SetString("32292934596187112148346015918544186536963932779440027682601542850818403729416", 10)
    43  	expectedTokenID1, _ := big.NewInt(0).SetString("32292934596187112148346015918544186536963932779440027682601542850818403729414", 10)
    44  
    45  	expectedCollectiblesData := []thirdparty.FullCollectibleData{
    46  		{
    47  			CollectibleData: thirdparty.CollectibleData{
    48  				ID: thirdparty.CollectibleUniqueID{
    49  					ContractID: thirdparty.ContractID{
    50  						ChainID: 1,
    51  						Address: common.HexToAddress("0xb66a603f4cfe17e3d27b87a8bfcad319856518b8"),
    52  					},
    53  					TokenID: &bigint.BigInt{
    54  						Int: expectedTokenID0,
    55  					},
    56  				},
    57  				ContractType: w_common.ContractTypeUnknown,
    58  				Provider:     "rarible",
    59  				Name:         "Rariversary #002",
    60  				Description:  "Today marks your Second Rariversary! Can you believe it’s already been two years? Time flies when you’re having fun! Thank you for everything you contribute!",
    61  				Permalink:    "https://rarible.com/token/0xb66a603f4cfe17e3d27b87a8bfcad319856518b8:32292934596187112148346015918544186536963932779440027682601542850818403729416",
    62  				ImageURL:     "https://lh3.googleusercontent.com/03DCIWuHtWUG5zIPAkdBjPAucg-BNu-917hsY1LRyEtG9pMcYSwIv5n_jZoK4bvMjNbw9MEC3AZA29kje83fCf2XwG6WegOv0JU=s1000",
    63  				AnimationURL: "https://ipfs.raribleuserdata.com/ipfs/bafybeibpqyrvdkw7ypajsmsvjiz2mhytv7fyyfa6n35tfui7e473dxnyom/image.png",
    64  				Traits: []thirdparty.CollectibleTrait{
    65  					{
    66  						TraitType: "Theme",
    67  						Value:     "Luv U",
    68  					},
    69  					{
    70  						TraitType: "Gift for",
    71  						Value:     "Rariversary",
    72  					},
    73  					{
    74  						TraitType: "Year",
    75  						Value:     "2",
    76  					},
    77  				},
    78  				TokenURI: "ipfs://ipfs/bafkreialxjfvfkn43jluxmilfg3d3ojnomtqg634nuowqq2syx4odqrx5m",
    79  			},
    80  		},
    81  		{
    82  			CollectibleData: thirdparty.CollectibleData{
    83  				ID: thirdparty.CollectibleUniqueID{
    84  					ContractID: thirdparty.ContractID{
    85  						ChainID: 1,
    86  						Address: common.HexToAddress("0xb66a603f4cfe17e3d27b87a8bfcad319856518b8"),
    87  					},
    88  					TokenID: &bigint.BigInt{
    89  						Int: expectedTokenID1,
    90  					},
    91  				},
    92  				ContractType: w_common.ContractTypeUnknown,
    93  				Provider:     "rarible",
    94  				Name:         "Rariversary #003",
    95  				Description:  "Today marks your Third Rariversary! Can you believe it’s already been three years? Time flies when you’re having fun! We’ve loved working with you these years and can’t wait to see what the next few years bring. Thank you for everything you contribute!",
    96  				Permalink:    "https://rarible.com/token/0xb66a603f4cfe17e3d27b87a8bfcad319856518b8:32292934596187112148346015918544186536963932779440027682601542850818403729414",
    97  				ImageURL:     "https://lh3.googleusercontent.com/SimzYIBjaTFt3BTBXFGOOvAqfw_etV0Pbe2pen-IvwF7L8DOysNca7qBdj3Dt5n_HWsse5vDLD7FZ7o5XdEivRvBtUybI1mXZEBQ=s1000",
    98  				AnimationURL: "https://ipfs.raribleuserdata.com/ipfs/bafybeicsr36faeleunc5pzkqyf57pwm66vir4xhdkvv6cnkkznoyewqt7u/image.png",
    99  				Traits: []thirdparty.CollectibleTrait{
   100  					{
   101  						TraitType: "Theme",
   102  						Value:     "LFG",
   103  					},
   104  					{
   105  						TraitType: "Gift for",
   106  						Value:     "Rariversary",
   107  					},
   108  					{
   109  						TraitType: "Year",
   110  						Value:     "3",
   111  					},
   112  				},
   113  				TokenURI: "ipfs://ipfs/bafkreifeaueluerp33pjevz56f3ioxv63z73zuvm4wku5k6sobvala4phe",
   114  			},
   115  		},
   116  	}
   117  
   118  	var container CollectiblesContainer
   119  	err := json.Unmarshal([]byte(ownedCollectiblesJSON), &container)
   120  	assert.NoError(t, err)
   121  
   122  	collectiblesData := raribleToCollectiblesData(container.Collectibles, true)
   123  
   124  	assert.Equal(t, expectedCollectiblesData, collectiblesData)
   125  }