Refactored to work with types repo @3af92598

This commit is contained in:
Mark Beamer Jr 2019-04-21 23:06:48 -04:00
parent bad2d869f5
commit 322c658307
No known key found for this signature in database
GPG key ID: 1C314FB89AD76973
4 changed files with 69 additions and 54 deletions

View file

@ -69,15 +69,14 @@ func TestCreateChannelClaim(t *testing.T) {
}
claim := &ClaimHelper{Claim: newChannelClaim(), Version: NoSig}
claim.GetChannel().PublicKey = pubKeyBytes
claim.GetChannel().Title = "Test Channel Title"
claim.GetChannel().Description = "Test Channel Description"
claim.GetChannel().CoverUrl = "http://testcoverurl.com"
claim.GetChannel().Tags = []string{"TagA", "TagB", "TagC"}
claim.GetChannel().Languages = []*pb.Language{{Language: pb.Language_en}, {Language: pb.Language_es}}
claim.GetChannel().ThumbnailUrl = "http://thumbnailurl.com"
claim.GetChannel().ContactEmail = "test@test.com"
claim.GetChannel().HomepageUrl = "http://homepageurl.com"
claim.GetChannel().Locations = []*pb.Location{{Country: pb.Location_AD}, {Country: pb.Location_US, State: "NJ", City: "some city"}}
claim.Title = "Test Channel Title"
claim.Description = "Test Channel Description"
claim.GetChannel().Cover = &pb.Source{Url: "http://testcoverurl.com"}
claim.Tags = []string{"TagA", "TagB", "TagC"}
claim.Languages = []*pb.Language{{Language: pb.Language_en}, {Language: pb.Language_es}}
claim.Thumbnail = &pb.Source{Url: "http://thumbnailurl.com"}
claim.GetChannel().WebsiteUrl = "http://homepageurl.com"
claim.Locations = []*pb.Location{{Country: pb.Location_AD}, {Country: pb.Location_US, State: "NJ", City: "some city"}}
rawClaim, err := claim.CompileValue()
if err != nil {

View file

@ -15,7 +15,6 @@ const lbrySDHash = "lbry_sd_hash"
func newStreamClaim() *pb.Claim {
claimStream := new(pb.Claim_Stream)
stream := new(pb.Stream)
stream.File = new(pb.File)
pbClaim := new(pb.Claim)
pbClaim.Type = claimStream
@ -35,16 +34,22 @@ func newChannelClaim() *pb.Claim {
return pbClaim
}
func setMetaData(claim pb.Claim, author string, description string, language pb.Language_Language, license string,
func setMetaData(claim *pb.Claim, author string, description string, language pb.Language_Language, license string,
licenseURL *string, title string, thumbnail *string, nsfw bool) {
claim.Title = title
claim.Description = description
claim.GetStream().Author = author
claim.GetStream().Description = description
claim.GetStream().Languages = []*pb.Language{{Language: language}}
claim.GetStream().Title = title
claim.Languages = []*pb.Language{{Language: language}}
if thumbnail != nil {
claim.GetStream().ThumbnailUrl = *thumbnail
source := new(pb.Source)
source.Url = *thumbnail
claim.Thumbnail = source
}
if nsfw {
claim.Tags = []string{"mature"}
}
claim.GetStream().Tags = []string{"mature"}
claim.GetStream().License = license
if licenseURL != nil {
claim.GetStream().LicenseUrl = *licenseURL
@ -63,7 +68,10 @@ func migrateV1PBClaim(vClaim v1pb.Claim) (*pb.Claim, error) {
func migrateV1PBStream(vClaim v1pb.Claim) (*pb.Claim, error) {
claim := newStreamClaim()
claim.GetStream().MediaType = vClaim.GetStream().GetSource().GetContentType()
source := new(pb.Source)
source.MediaType = vClaim.GetStream().GetSource().GetContentType()
source.SdHash = vClaim.GetStream().GetSource().GetSource()
claim.GetStream().Source = source
md := vClaim.GetStream().GetMetadata()
if md.GetFee() != nil {
claim.GetStream().Fee = new(pb.Fee)
@ -71,17 +79,18 @@ func migrateV1PBStream(vClaim v1pb.Claim) (*pb.Claim, error) {
claim.GetStream().GetFee().Address = md.GetFee().GetAddress()
claim.GetStream().GetFee().Currency = pb.Fee_Currency(pb.Fee_Currency_value[md.GetFee().GetCurrency().String()])
}
claim.GetStream().SdHash = vClaim.GetStream().GetSource().GetSource()
if vClaim.GetStream().GetMetadata().GetNsfw() {
claim.GetStream().Tags = []string{"mature"}
claim.Tags = []string{"mature"}
}
claim.GetStream().ThumbnailUrl = md.GetThumbnail()
thumbnailSource := new(pb.Source)
thumbnailSource.Url = md.GetThumbnail()
claim.Thumbnail = thumbnailSource
language := pb.Language_Language(pb.Language_Language_value[md.GetLanguage().String()])
claim.GetStream().Languages = []*pb.Language{{Language: language}}
claim.Languages = []*pb.Language{{Language: language}}
claim.GetStream().LicenseUrl = md.GetLicenseUrl()
claim.GetStream().License = md.GetLicense()
claim.GetStream().Title = md.GetTitle()
claim.GetStream().Description = md.GetDescription()
claim.Title = md.GetTitle()
claim.Description = md.GetDescription()
claim.GetStream().Author = md.GetAuthor()
return claim, nil
@ -101,15 +110,18 @@ func migrateV1Claim(vClaim V1Claim) (*pb.Claim, error) {
setFee(vClaim.Fee, pbClaim)
// -->MetaData
language := pb.Language_Language(pb.Language_Language_value[vClaim.Language])
setMetaData(*pbClaim, vClaim.Author, vClaim.Description, language,
setMetaData(pbClaim, vClaim.Author, vClaim.Description, language,
vClaim.License, nil, vClaim.Title, vClaim.Thumbnail, false)
// -->Source
pbClaim.GetStream().MediaType = vClaim.ContentType
source := new(pb.Source)
source.MediaType = vClaim.ContentType
src, err := hex.DecodeString(vClaim.Sources.LbrySDHash)
if err != nil {
return nil, errors.Err(err)
}
pbClaim.GetStream().SdHash = src
source.SdHash = src
pbClaim.GetStream().Source = source
return pbClaim, nil
}
@ -121,15 +133,17 @@ func migrateV2Claim(vClaim V2Claim) (*pb.Claim, error) {
setFee(vClaim.Fee, pbClaim)
// -->MetaData
language := pb.Language_Language(pb.Language_Language_value[vClaim.Language])
setMetaData(*pbClaim, vClaim.Author, vClaim.Description, language,
setMetaData(pbClaim, vClaim.Author, vClaim.Description, language,
vClaim.License, vClaim.LicenseURL, vClaim.Title, vClaim.Thumbnail, vClaim.NSFW)
// -->Source
pbClaim.GetStream().MediaType = vClaim.ContentType
source := new(pb.Source)
source.MediaType = vClaim.ContentType
src, err := hex.DecodeString(vClaim.Sources.LbrySDHash)
if err != nil {
return nil, errors.Err(err)
}
pbClaim.GetStream().SdHash = src
source.SdHash = src
pbClaim.GetStream().Source = source
return pbClaim, nil
}
@ -141,15 +155,17 @@ func migrateV3Claim(vClaim V3Claim) (*pb.Claim, error) {
setFee(vClaim.Fee, pbClaim)
// -->MetaData
language := pb.Language_Language(pb.Language_Language_value[vClaim.Language])
setMetaData(*pbClaim, vClaim.Author, vClaim.Description, language,
setMetaData(pbClaim, vClaim.Author, vClaim.Description, language,
vClaim.License, vClaim.LicenseURL, vClaim.Title, vClaim.Thumbnail, vClaim.NSFW)
// -->Source
pbClaim.GetStream().MediaType = vClaim.ContentType
source := new(pb.Source)
source.MediaType = vClaim.ContentType
src, err := hex.DecodeString(vClaim.Sources.LbrySDHash)
if err != nil {
return nil, errors.Err(err)
}
pbClaim.GetStream().SdHash = src
source.SdHash = src
pbClaim.GetStream().Source = source
return pbClaim, nil
}

View file

@ -191,11 +191,11 @@ func TestMigrationFromJSON(t *testing.T) {
if helper.Claim.GetStream().GetAuthor() != pair.Claim.Author {
t.Error("Author mismatch: expected", pair.Claim.Author, "got", helper.Claim.GetStream().GetAuthor())
}
if helper.Claim.GetStream().GetTitle() != pair.Claim.Title {
t.Error("Title mismatch: expected", pair.Claim.Title, "got", helper.Claim.GetStream().GetTitle())
if helper.Claim.GetTitle() != pair.Claim.Title {
t.Error("Title mismatch: expected", pair.Claim.Title, "got '", helper.Claim.GetTitle(), "'")
}
if helper.Claim.GetStream().GetDescription() != pair.Claim.Description {
t.Error("Description mismatch: expected", pair.Claim.Description, "got", helper.Claim.GetStream().GetDescription())
if helper.Claim.GetDescription() != pair.Claim.Description {
t.Error("Description mismatch: expected", pair.Claim.Description, "got '", helper.Claim.GetDescription(), "'")
}
if helper.Claim.GetStream().GetLicense() != pair.Claim.License {
t.Error("License mismatch: expected", pair.Claim.License, "got", helper.Claim.GetStream().GetLicense())
@ -213,13 +213,13 @@ func TestMigrationFromJSON(t *testing.T) {
if hexaddress != pair.Claim.FeeAddress {
t.Error("Fee Address mismatch: expected", pair.Claim.FeeAddress, "got", hexaddress)
}
if helper.Claim.GetStream().GetMediaType() != pair.Claim.ContentType {
t.Error("ContentType mismatch: expected", pair.Claim.ContentType, "got", helper.Claim.GetStream().GetMediaType())
if helper.Claim.GetStream().GetSource().GetMediaType() != pair.Claim.ContentType {
t.Error("ContentType mismatch: expected", pair.Claim.ContentType, "got", helper.Claim.GetStream().GetSource().GetMediaType())
}
if helper.Claim.GetStream().GetLanguages()[0].String() != pair.Claim.Language {
t.Error("Language mismatch: expected ", pair.Claim.Language, " got ", helper.Claim.GetStream().GetLanguages()[0].String())
if helper.Claim.GetLanguages()[0].String() != pair.Claim.Language {
t.Error("Language mismatch: expected ", pair.Claim.Language, " got ", helper.Claim.GetLanguages()[0].String())
}
content := hex.EncodeToString(helper.Claim.GetStream().GetSdHash())
content := hex.EncodeToString(helper.Claim.GetStream().GetSource().GetSdHash())
if content != pair.Claim.LbrySDHash {
t.Error("Source mismatch: expected", pair.Claim.LbrySDHash, "got", content)
}
@ -232,18 +232,18 @@ func TestMigrationFromV1YTSync(t *testing.T) {
if err != nil {
t.Error(err)
}
assert.Assert(t, claim.GetStream().GetTitle() == "Here are 5 Reasons I ❤️ Nextcloud | TLG")
assert.Assert(t, claim.GetStream().GetDescription() == "Find out more about Nextcloud: https://nextcloud.com/\n\nYou can find me on these socials:\n * Forums: https://forum.heavyelement.io/\n * Podcast: https://offtopical.net\n * Patreon: https://patreon.com/thelinuxgamer\n * Merch: https://teespring.com/stores/official-linux-gamer\n * Twitch: https://twitch.tv/xondak\n * Twitter: https://twitter.com/thelinuxgamer\n\n...\nhttps://www.youtube.com/watch?v=FrTdBCOS_fc")
assert.Assert(t, claim.GetTitle() == "Here are 5 Reasons I ❤️ Nextcloud | TLG")
assert.Assert(t, claim.GetDescription() == "Find out more about Nextcloud: https://nextcloud.com/\n\nYou can find me on these socials:\n * Forums: https://forum.heavyelement.io/\n * Podcast: https://offtopical.net\n * Patreon: https://patreon.com/thelinuxgamer\n * Merch: https://teespring.com/stores/official-linux-gamer\n * Twitch: https://twitch.tv/xondak\n * Twitter: https://twitter.com/thelinuxgamer\n\n...\nhttps://www.youtube.com/watch?v=FrTdBCOS_fc")
assert.Assert(t, claim.GetStream().GetLicense() == "Copyrighted (contact author)")
assert.Assert(t, claim.GetStream().GetAuthor() == "The Linux Gamer")
//?assert.Assert(t, claim.GetStream().GetLanguages()[0])
assert.Assert(t, claim.GetStream().GetMediaType() == "video/mp4")
assert.Assert(t, claim.GetStream().GetThumbnailUrl() == "https://berk.ninja/thumbnails/FrTdBCOS_fc")
assert.Assert(t, claim.GetStream().GetSource().GetMediaType() == "video/mp4")
assert.Assert(t, claim.GetThumbnail().GetUrl() == "https://berk.ninja/thumbnails/FrTdBCOS_fc")
sdHashBytes, err := hex.DecodeString("040e8ac6e89c061f982528c23ad33829fd7146435bf7a4cc22f0bff70c4fe0b91fd36da9a375e3e1c171db825bf5d1f3")
if err != nil {
t.Error(err)
}
assert.Assert(t, bytes.Equal(claim.GetStream().GetSdHash(), sdHashBytes))
assert.Assert(t, bytes.Equal(claim.GetStream().GetSource().GetSdHash(), sdHashBytes))
channelHex := "08011002225e0801100322583056301006072a8648ce3d020106052b8104000a034200043878b1edd4a1373149909ef03f4339f6da9c2bd2214c040fd2e530463ffe66098eca14fc70b50ff3aefd106049a815f595ed5a13eda7419ad78d9ed7ae473f17"
channel, err := DecodeClaimHex(channelHex, "lbrycrd_main")
@ -263,17 +263,17 @@ func TestMigrationFromV1UnsignedWithFee(t *testing.T) {
if err != nil {
t.Error(err)
}
assert.Assert(t, claim.GetStream().GetTitle() == "rpg midi")
assert.Assert(t, claim.GetStream().GetDescription() == "midi")
assert.Assert(t, claim.GetTitle() == "rpg midi")
assert.Assert(t, claim.GetDescription() == "midi")
assert.Assert(t, claim.GetStream().GetLicense() == "Creative Commons Attribution 4.0 International")
assert.Assert(t, claim.GetStream().GetAuthor() == "rpg midi")
//assert.Assert(t, claim.GetStream().GetLanguage() == "en")
assert.Assert(t, claim.GetStream().GetMediaType() == "application/x-zip-compressed")
assert.Assert(t, claim.GetStream().GetSource().GetMediaType() == "application/x-zip-compressed")
sdHashBytes, err := hex.DecodeString("1f41eb0312aa7e8a5ce49349bc77d811da975833719d751523b19f123fc3d528d6a94e3446ccddb7b9329f27a9cad7e3")
if err != nil {
t.Error(err)
}
assert.Assert(t, bytes.Equal(claim.GetStream().GetSdHash(), sdHashBytes))
assert.Assert(t, bytes.Equal(claim.GetStream().GetSource().GetSdHash(), sdHashBytes))
feeAddressBytes, err := address.DecodeAddress("bJUQ9MxS9N6M29zsA5GTpVSDzsnPjMBBX9", "lbrycrd_main")
assert.Assert(t, bytes.Equal(claim.GetStream().GetFee().GetAddress(), feeAddressBytes[:]))
assert.Assert(t, claim.GetStream().GetFee().GetAmount() == 1500000000)

View file

@ -30,8 +30,8 @@ func TestSign(t *testing.T) {
}
claim := &ClaimHelper{newStreamClaim(), nil, reverseBytes(claimIDHexBytes), WithSig, nil}
claim.Claim.GetStream().Title = "Test title"
claim.Claim.GetStream().Description = "Test description"
claim.Claim.Title = "Test title"
claim.Claim.Description = "Test description"
sig, err := Sign(*privateKey, *channel, *claim, txid)
if err != nil {
t.Error(err)
@ -105,8 +105,8 @@ func TestSignWithV1Channel(t *testing.T) {
}
claim := &ClaimHelper{newStreamClaim(), nil, reverseBytes(claimIDHexBytes), WithSig, nil}
claim.Claim.GetStream().Title = "Test title"
claim.Claim.GetStream().Description = "Test description"
claim.Claim.Title = "Test title"
claim.Claim.Description = "Test description"
sig, err := Sign(*privateKey, *channel, *claim, txid)
if err != nil {
t.Error(err)