mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-04 06:32:59 +00:00
store: answer community in the registration view
This commit is contained in:
1 parent
93e34988a6
commit
66fbc457ab
2 files changed
+19
-4
No files matched your search
@@ -34,6 +34,7 @@ import Simplex.Messaging.Util (safeDecodeUtf8)
|
||||
import StoreService.Config (ChainConfig (..), NamesConfig (..))
|
||||
import StoreService.Names.Abi (hex)
|
||||
import StoreService.Names.Chain (TxHash (..))
|
||||
import StoreService.Names.Community (communityJSON)
|
||||
import StoreService.Names.Contracts (Contracts, sponsorNonce)
|
||||
import StoreService.Names.Phases (RegistrationId (..))
|
||||
import StoreService.Names.Store (Balance (..), BalanceHold (..), LateWait (..), NamePhase (..), NameRegistration (..), NameReveal (..), RegistrationPayment (..), getBalance, getRegistration, heldBy, lateWait)
|
||||
@@ -67,7 +68,7 @@ readViewChain ct NameRegistration {nrPhase, nrOwner} = case nrPhase of
|
||||
none = ViewReads {vrIntentNonce = Nothing, vrUnread = []}
|
||||
|
||||
viewJSON :: NamesConfig -> NameRegistration -> Maybe Balance -> Maybe LateWait -> ViewReads -> J.Value
|
||||
viewJSON NamesConfig {nTLD, nChain = ChainConfig {cChainId, cResolver, cSponsor}} r balance late ViewReads {vrIntentNonce, vrUnread} =
|
||||
viewJSON cfg@NamesConfig {nTLD, nChain = ChainConfig {cChainId, cResolver, cSponsor}} r balance late ViewReads {vrIntentNonce, vrUnread} =
|
||||
J.object
|
||||
[ "id" .= rid,
|
||||
"version" .= nrVersion,
|
||||
@@ -96,7 +97,8 @@ viewJSON NamesConfig {nTLD, nChain = ChainConfig {cChainId, cResolver, cSponsor}
|
||||
"intentNonce" .= vrIntentNonce,
|
||||
"unread" .= vrUnread,
|
||||
"expiresAt" .= nrExpiresAt,
|
||||
"error" .= nrError
|
||||
"error" .= nrError,
|
||||
"community" .= communityJSON cfg (nrLabelHash r)
|
||||
]
|
||||
where
|
||||
NameRegistration {nrId = RegistrationId rid, nrVersion, nrMoves, nrLinksRefusedAt, nrPhase, nrLabelHash = LabelHash lh, nrReveal, nrOwner, nrCommitment, nrSealed} = r
|
||||
|
||||
@@ -175,6 +175,7 @@ namesOrdersTests = describe "StoreService names: orders" $ do
|
||||
it "agrees between the sweep and the overdue close on which invoices hold money" testFundedAgreement
|
||||
describe "registration view" $ do
|
||||
it "has the contract's fields" testViewFields
|
||||
it "has the community entry of its label hash, null for an unlisted name" testViewCommunity
|
||||
it "reads the intent nonce in committed and nothing in taken" testViewReads
|
||||
it "leaves a failed intentNonce read null and named in unread, reading nothing in taken" testViewUnread
|
||||
it "reads the order's balance, held until its holder's invoice expires and free past it, and the cents its order took from another's" testViewBalance
|
||||
@@ -1373,12 +1374,12 @@ testViewFields = withServiceStore $ \st -> withFakeEthNode $ \node -> do
|
||||
sort (KM.keys v)
|
||||
`shouldBe` sort
|
||||
[ "id", "version", "moves", "linksRefused", "phase", "labelHash", "label", "owner", "commitment", "sealed", "resolver", "sponsor", "chainId", "tld",
|
||||
"years", "duration", "price", "fromBalance", "balance", "latePayment", "commitTx", "registerTx", "revealAfter", "revealBefore", "intentNonce", "unread", "expiresAt", "error"
|
||||
"years", "duration", "price", "fromBalance", "balance", "latePayment", "commitTx", "registerTx", "revealAfter", "revealBefore", "intentNonce", "unread", "expiresAt", "error", "community"
|
||||
]
|
||||
field "latePayment" v `shouldBe` Just J.Null
|
||||
let waiting w = field "latePayment" $ objectOf $ viewJSON (testNamesConfig node) r Nothing (Just w) ViewReads {vrIntentNonce = Nothing, vrUnread = []}
|
||||
map waiting [LWConfirming, LWCrediting, LWSupport] `shouldBe` map (\t -> Just $ J.object ["waiting" .= (t :: Text)]) ["confirming", "crediting", "support"]
|
||||
map (`field` v) ["id", "phase", "owner", "tld", "chainId", "linksRefused", "label", "unread", "sponsor", "fromBalance", "balance"]
|
||||
map (`field` v) ["id", "phase", "owner", "tld", "chainId", "linksRefused", "label", "unread", "sponsor", "fromBalance", "balance", "community"]
|
||||
`shouldBe` map
|
||||
Just
|
||||
[ "r1",
|
||||
@@ -1391,9 +1392,21 @@ testViewFields = withServiceStore $ \st -> withFakeEthNode $ \node -> do
|
||||
J.Array mempty,
|
||||
J.String $ safeDecodeUtf8 $ strEncode fakeSponsor,
|
||||
J.Number 0,
|
||||
J.Null,
|
||||
J.Null
|
||||
]
|
||||
|
||||
testViewCommunity :: IO ()
|
||||
testViewCommunity = withServiceStore $ \st -> withFakeEthNode $ \node -> do
|
||||
Right () <- placePaid st "r1" ownerA (order "alicebakery" 1) (addUTCTime 3600 t0)
|
||||
r <- withTransaction st $ \db -> fromJust <$> getRegistration db (RegistrationId "r1")
|
||||
let LabelHash aliceHash = labelHash "alicebakery"
|
||||
listing :: [(ByteString, Text)] -> Maybe J.Value
|
||||
listing entries = field "community" $ objectOf $ viewJSON (testNamesConfig node) {nCommunity = M.fromList entries} r Nothing Nothing ViewReads {vrIntentNonce = Nothing, vrUnread = []}
|
||||
listing [(aliceHash, "bakers and bakeries in Lisbon")] `shouldBe` Just (J.object ["for" .= ("bakers and bakeries in Lisbon" :: Text)])
|
||||
let LabelHash bobHash = labelHash "bobsbakery"
|
||||
listing [(bobHash, "bakers of Porto")] `shouldBe` Just J.Null
|
||||
|
||||
testViewReads :: IO ()
|
||||
testViewReads = withServiceStore $ \st -> withFakeEthNode $ \node -> do
|
||||
g <- C.newRandom
|
||||
|
||||
Reference in new issue
Block a user