github.com/status-im/status-go@v1.1.0/services/wallet/thirdparty/alchemy/client_test.go (about) 1 package alchemy 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: "alchemy", 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: &thirdparty.CollectionSocials{Website: "", TwitterHandle: "CryptoKitties", Provider: "alchemy"}, 28 } 29 30 collection := Contract{} 31 err := json.Unmarshal([]byte(collectionJSON), &collection) 32 assert.NoError(t, err) 33 34 contractID := thirdparty.ContractID{ 35 ChainID: 1, 36 Address: common.HexToAddress("0x06012c8cf97bead5deae237070f9587f8e7a266d"), 37 } 38 39 collectionData := collection.toCollectionData(contractID) 40 assert.Equal(t, expectedCollectionData, collectionData) 41 } 42 43 func TestUnmarshallOwnedCollectibles(t *testing.T) { 44 expectedTokenID0, _ := big.NewInt(0).SetString("50659039041325838222074459099120411190538227963344971355684955900852972814336", 10) 45 expectedTokenID1, _ := big.NewInt(0).SetString("900", 10) 46 47 expectedBalance0, _ := big.NewInt(0).SetString("15", 10) 48 expectedBalance1, _ := big.NewInt(0).SetString("1", 10) 49 50 expectedCollectiblesData := []thirdparty.FullCollectibleData{ 51 { 52 CollectibleData: thirdparty.CollectibleData{ 53 ID: thirdparty.CollectibleUniqueID{ 54 ContractID: thirdparty.ContractID{ 55 ChainID: 1, 56 Address: common.HexToAddress("0x2b1870752208935fDA32AB6A016C01a27877CF12"), 57 }, 58 TokenID: &bigint.BigInt{ 59 Int: expectedTokenID0, 60 }, 61 }, 62 ContractType: w_common.ContractTypeERC1155, 63 Provider: "alchemy", 64 Name: "HODL", 65 Description: "The enemy king sent a single message, written on a parchment stained by blood.\n“You are advised to submit without further delay, for if I bring my army into your land, I will destroy your hodlings, slay your people, and burn your city to ashes.”\nHodlers of ENJ sent a single word as reply:\n“If.”\nThe battle that followed does not come around too often, a battle that began every legend told about the warriors that gained eternal glory. \nThe battle that followed seemed like a lost one from the very beginning. \nThe enemy army was revealed at dawn, illuminated by the rising Sun.The ground shook as countless hordes marched towards a small band of men armed with shields, spears and swords.\nThe hodlers were outnumbered, one thousand to one. \nFear, doubt and uncertainty did not reach their hearts and minds - for they were born for this. \nEach hodler was bred for warfare, instructed in bloodshed, groomed to become a poet of death. \nA philosopher of war, blood and glory. \nEach man was forged into an invincible soldier that had a single driving force during each battle.\nStand your ground - at all costs. \nAs the swarm of enemies approached, the king yelled, asking his men: \n“Hodlers! What is your profession?”\n“HODL! HODL! HODL! HODL!!! HODL!!!!!” they replied, hitting spears against their shields. \nAn endless stream of arrows fell from the heavens only moments later, blocking out the Sun so they could fight in the shade. They emerged from the darkness without even a single scratch, protected by their legendary Enjin shields. \nWave after wave, their enemies rushed towards their doom, as they were met with cold tips of thrusting spears and sharp edges of crimson swords.\nAgainst all odds, the wall of men and steel held against the never-ending, shilling swarm. \nWhat was left of the enemy army retreated, fleeing in absolute panic and indisputable terror.\nBathed in blood, the ENJ hodlers were victorious.\nTheir story will be told for thousands of years, immortalized with divine blocks and chains.\n* * *\n“HODL” was minted in 2018 for our amazing community of epic Enjin HODLers. We are extremely grateful for the trust you've put in us and the products we're making - and the mission we're trying to accomplish, and hope you’ll love this token of our appreciation. ", // nolint: misspell 66 Permalink: "", 67 ImageURL: "https://res.cloudinary.com/alchemyapi/image/upload/convert-png/eth-mainnet/c5c93ffa8146ade7d3694c0f28463f0c", 68 AnimationURL: "https://nft-cdn.alchemy.com/eth-mainnet/c5c93ffa8146ade7d3694c0f28463f0c", 69 Traits: []thirdparty.CollectibleTrait{}, 70 TokenURI: "https://cdn.enjin.io/mint/meta/70000000000001b2.json", 71 }, 72 CollectionData: &thirdparty.CollectionData{ 73 ID: thirdparty.ContractID{ 74 ChainID: 1, 75 Address: common.HexToAddress("0x2b1870752208935fDA32AB6A016C01a27877CF12"), 76 }, 77 ContractType: w_common.ContractTypeERC1155, 78 Provider: "alchemy", 79 Name: "", 80 Slug: "", 81 ImageURL: "", 82 Traits: make(map[string]thirdparty.CollectionTrait), 83 Socials: &thirdparty.CollectionSocials{Website: "", TwitterHandle: "", Provider: "alchemy"}, 84 }, 85 AccountBalance: &bigint.BigInt{ 86 Int: expectedBalance0, 87 }, 88 }, 89 { 90 CollectibleData: thirdparty.CollectibleData{ 91 ID: thirdparty.CollectibleUniqueID{ 92 ContractID: thirdparty.ContractID{ 93 ChainID: 1, 94 Address: common.HexToAddress("0x3f6B1585AfeFc56433C8d28AA89dbc77af59278f"), 95 }, 96 TokenID: &bigint.BigInt{ 97 Int: expectedTokenID1, 98 }, 99 }, 100 ContractType: w_common.ContractTypeERC721, 101 Provider: "alchemy", 102 Name: "#900", 103 Description: "5,555 SimpsonPunks entered the Ethereum Blockchain🍩", 104 Permalink: "", 105 ImageURL: "https://res.cloudinary.com/alchemyapi/image/upload/convert-png/eth-mainnet/52accf48dc609088738b15808fe07e8c", 106 AnimationURL: "https://nft-cdn.alchemy.com/eth-mainnet/52accf48dc609088738b15808fe07e8c", 107 Traits: []thirdparty.CollectibleTrait{ 108 { 109 TraitType: "layers", 110 Value: "Background", 111 }, 112 { 113 TraitType: "Face", 114 Value: "Monkey", 115 }, 116 { 117 TraitType: "Head", 118 Value: "Sweatband Blue", 119 }, 120 { 121 TraitType: "Facial Hair", 122 Value: "Thin Full", 123 }, 124 { 125 TraitType: "Mouth", 126 Value: "Burger", 127 }, 128 }, 129 TokenURI: "https://alchemy.mypinata.cloud/ipfs/bafybeidqbmbglapk2bkffa4o2ws5jhxnhlbdeqh7k6tk62pukse3xhvv2e/900.json", 130 }, 131 CollectionData: &thirdparty.CollectionData{ 132 ID: thirdparty.ContractID{ 133 ChainID: 1, 134 Address: common.HexToAddress("0x3f6B1585AfeFc56433C8d28AA89dbc77af59278f"), 135 }, 136 ContractType: w_common.ContractTypeERC721, 137 Provider: "alchemy", 138 Name: "Simpson Punk", 139 Slug: "", 140 ImageURL: "https://raw.seadn.io/files/e7765f13c4658f514d0efc008ae7f300.png", 141 Traits: make(map[string]thirdparty.CollectionTrait), 142 Socials: &thirdparty.CollectionSocials{Website: "", TwitterHandle: "SimpsonPunksETH", Provider: "alchemy"}, 143 }, 144 AccountBalance: &bigint.BigInt{ 145 Int: expectedBalance1, 146 }, 147 }, 148 } 149 150 var container OwnedNFTList 151 err := json.Unmarshal([]byte(ownedCollectiblesJSON), &container) 152 assert.NoError(t, err) 153 154 collectiblesData := alchemyToCollectiblesData(w_common.ChainID(w_common.EthereumMainnet), container.OwnedNFTs) 155 156 assert.Equal(t, expectedCollectiblesData, collectiblesData) 157 }