2020-10-28 06:36:49 +01:00
package stake
2018-11-09 18:10:58 +01:00
import (
2019-04-07 06:29:12 +02:00
"bytes"
2018-11-09 18:10:58 +01:00
"encoding/hex"
2018-11-09 22:39:27 +01:00
"fmt"
2018-11-09 18:10:58 +01:00
"testing"
2021-10-06 20:00:59 +02:00
"github.com/lbryio/lbry.go/v3/schema/address"
2019-04-07 06:29:12 +02:00
2021-10-06 20:00:59 +02:00
"github.com/lbryio/lbcutil/base58"
2019-04-07 06:29:12 +02:00
"gotest.tools/assert"
2018-11-09 18:10:58 +01:00
)
type valueTestPair struct {
ValueAsHex string
Claim claimResult
}
type claimResult struct {
Version string
Author string
Title string
Description string
License string
LicenseURL string
FeeAmount float32
FeeCurrency string
FeeAddress string
ContentType string
Language string
LbrySDHash string
Thumbnail string
NSFW bool
}
2018-11-09 22:39:27 +01:00
var badJsonVersionTests = [ ] string {
"7b22666565223a20352c2022766572223a2022302e302e33222c20226c6963656e7365223a202247504c20332e30222c20226c616e6775616765223a2022656e222c2022617574686f72223a2022576f6e64657220576f6d616e2031393933222c20227469746c65223a2022576f6e64657220576f6d616e2031393933222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022323338663832363932356462323235353863646335636430373436303637626666393964636263333834333832666661303236646463373230373261366362323461393332346461373961626136643232373437313164653035353063396534227d2c20226e736677223a20747275652c2022636f6e74656e745f74797065223a2022696d6167652f6a706567222c20227468756d626e61696c223a2022687474703a2f2f692e696d6775722e636f6d2f4568344a4658732e6a7067222c20226465736372697074696f6e223a2022466f7220746865206c6f766521227d" ,
"7b22666565223a2022302e303031222c2022766572223a2022302e302e33222c20226465736372697074696f6e223a20224120717569636b206c6f6f6b2061742074686520536f6e79204c44502033363030204c617365726469736320706c61796572222c20226c6963656e7365223a20224c42525920696e63222c20227469746c65223a2022536f6e79204c44502033363030204c617365726469736320506c61796572222c2022617574686f72223a20225061756c204b6176616e616768222c20226c616e6775616765223a2022656e222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022393962383766363064643136643730316538613562666238353130633938343239623866633563656538623764663333643665666135386464313133313261333665616437303638643133636364636331383563376465613730643930393261227d2c2022636f6e74656e745f74797065223a2022766964656f2f6d7034222c20226e736677223a2066616c73657d" ,
"080110011ac3bd01080112c2b501080410011a0b57696e205465737420313122065465737420322a0444617665322e437265617469766520436f6d6d6f6e73204174747269627574696f6e20332e3020556e697465642053746174657338004224080110031a19556bc2a9c28bc2b057c3aec2901d5445c3b17cc384c3bd29c3b72b5f74101cc2aec2aac2a1250000c2b2424a0052005a3868747470733a2f2f6372656174697665636f6d6d6f6e732e6f72672f6c6963656e7365732f62792f332e302f75732f6c6567616c636f64651a41080110011a302a1ec2a42cc383223f7cc2b4c291353d0f687675c289c3a34cc3a73942c383c3abc3b7330dc3912d162ac388c3bec3a5c2aec293c2b1c38f68c3a2c2bfc2907a04c3b8c39dc2b1742209696d6167652f706e67" ,
"7b22666565223a2022302e303031222c2022766572223a2022302e302e33222c20226465736372697074696f6e223a20224120717569636b206c6f6f6b2061742074686520536f6e79204c44502033363030204c617365726469736320706c61796572222c20226c6963656e7365223a20224c42525920696e63222c20227469746c65223a2022536f6e79204c44502033363030204c617365726469736320506c61796572222c2022617574686f72223a20225061756c204b6176616e616768222c20226c616e6775616765223a2022656e222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022393962383766363064643136643730316538613562666238353130633938343239623866633563656538623764663333643665666135386464313133313261333665616437303638643133636364636331383563376465613730643930393261227d2c2022636f6e74656e745f74797065223a2022766964656f2f6d7034222c20226e736677223a2066616c73657d" ,
"7b22666565223a2022302e303031222c2022766572223a2022302e302e33222c20226465736372697074696f6e223a20224120717569636b206c6f6f6b2061742074686520536f6e79204c44502033363030204c617365726469736320706c61796572222c20226c6963656e7365223a20224c42525920696e63222c2022617574686f72223a20225061756c204b6176616e616768222c20227469746c65223a2022536f6e79204c44502033363030204c617365726469736320506c61796572222c20226c616e6775616765223a2022656e222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022626639663033333464623237393634303730663035636637356262376131626664663431363864356565376130633866373563663661623536653965633363643039633534636636383262353366316531353030363930616165353530663134227d2c2022636f6e74656e745f74797065223a2022766964656f2f6d7034222c20226e736677223a2066616c73657d" ,
"30383031313030313161356330383031313231343038303431303030316130303232303032613030333230303338303034613030353230303561303031613432303830313130303131613330333933333030616561386262623636613238613966633031316231666238373634636364386338323633656233343532623733303832363233656534356431363866646530343836346435303563376535396539353430636263643766623336323230613639366436313637363532663661373036353637" ,
2018-11-09 18:10:58 +01:00
}
var jsonVersionTests = [ ] valueTestPair {
{ "7b22666565223a207b224c4243223a207b22616d6f756e74223a20312e302c202261646472657373223a2022625077474139683775696a6f79357541767a565051773951794c6f595a6568484a6f227d7d2c20226465736372697074696f6e223a2022313030304d4220746573742066696c6520746f206d65617375726520646f776e6c6f6164207370656564206f6e204c627279207032702d6e6574776f726b2e222c20226c6963656e7365223a20224e6f6e65222c2022617574686f72223a2022726f6f74222c20226c616e6775616765223a2022456e676c697368222c20227469746c65223a2022313030304d4220737065656420746573742066696c65222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022626439343033336431336634663339303837303837303163616635363562666130396366616466326633346661646634613733666238366232393564316232316137653634383035393934653435623566626336353066333062616334383734227d2c2022636f6e74656e742d74797065223a20226170706c69636174696f6e2f6f637465742d73747265616d222c20227468756d626e61696c223a20222f686f6d65726f626572742f6c6272792f73706565642e6a7067227d" ,
claimResult { "0.0.1" ,
"root" ,
"1000MB speed test file" ,
"1000MB test file to measure download speed on Lbry p2p-network." ,
"None" ,
"" ,
1 ,
"LBC" ,
"bPwGA9h7uijoy5uAvzVPQw9QyLoYZehHJo" ,
"application/octet-stream" ,
2019-04-07 06:29:12 +02:00
"" , //"English" is not supported for conversion.
2018-11-09 18:10:58 +01:00
"bd94033d13f4f3908708701caf565bfa09cfadf2f34fadf4a73fb86b295d1b21a7e64805994e45b5fbc650f30bac4874" ,
"/homerobert/lbry/speed.jpg" ,
false ,
} ,
} ,
{ "7b22666565223a207b224c4243223a207b22616d6f756e74223a2035302e302c202261646472657373223a2022624c5673336966507275795a6e70596d46665432544c416d68715a76676a70514461227d7d2c20226465736372697074696f6e223a2022466f757220636f75706c6573206d65657420666f722053756e646179206272756e6368206f6e6c7920746f20646973636f76657220746865792061726520737475636b20696e206120686f75736520746f6765746865722061732074686520776f726c64206d61792062652061626f757420746f20656e642e222c20226c6963656e7365223a20224f7363696c6c6f73636f7065204c61626f7261746f72696573222c2022617574686f72223a20225772697474656e20616e6420646972656374656420627920546f646420426572676572222c20226c616e6775616765223a2022656e222c20227469746c65223a2022497427732061204469736173746572222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022646363316266323838393361353033376561623965346139636437613462666536663736616436633231393730656134636565653031323266353032656630373936353764346463613435366234626533323439383439633465313836386238227d2c2022636f6e74656e742d74797065223a2022766964656f2f717569636b74696d65222c20227468756d626e61696c223a2022687474703a2f2f69612e6d656469612d696d64622e636f6d2f696d616765732f4d2f4d5635424d5451774e6a597a4d5451304d6c35424d6c3542616e426e586b46745a5463774e44557a4f444d354e7740402e5f56315f5359313030305f4352302c302c3637332c313030305f414c5f2e6a7067227d" ,
claimResult { "0.0.1" ,
"Written and directed by Todd Berger" ,
"It's a Disaster" ,
"Four couples meet for Sunday brunch only to discover they are stuck in a house together as the world may be about to end." ,
"Oscilloscope Laboratories" ,
"" ,
50 ,
"LBC" ,
"bLVs3ifPruyZnpYmFfT2TLAmhqZvgjpQDa" ,
"video/quicktime" ,
2019-04-07 06:29:12 +02:00
"language:en " ,
2018-11-09 18:10:58 +01:00
"dcc1bf28893a5037eab9e4a9cd7a4bfe6f76ad6c21970ea4ceee0122f502ef079657d4dca456b4be3249849c4e1868b8" ,
"http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg" ,
false ,
} ,
} ,
{ "7b226465736372697074696f6e223a202241647669736f7220416c6578205461626172726f6b206769766573206869732074616b65206f6e204c4252592e222c20226c6963656e7365223a20224c4252592c20496e632e222c2022617574686f72223a202253616d75656c20427279616e222c20226c616e6775616765223a2022656e222c20227469746c65223a20224d65657420746865205465616d20457069736f64652031222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022373939613164653933623865353536643766363638313033613666666334386163356664363830316464346438396361653637373363383064383163323833373130666434666432356564363864306462656565323638663832393134313435227d2c2022636f6e74656e742d74797065223a2022766964656f2f6d7034227d" ,
claimResult { "0.0.1" ,
"Samuel Bryan" ,
"Meet the Team Episode 1" ,
"Advisor Alex Tabarrok gives his take on LBRY." ,
"LBRY, Inc." ,
"" ,
0 ,
"UNKNOWN_CURRENCY" ,
"" ,
"video/mp4" ,
2019-04-07 06:29:12 +02:00
"language:en " ,
2018-11-09 18:10:58 +01:00
"799a1de93b8e556d7f668103a6ffc48ac5fd6801dd4d89cae6773c80d81c283710fd4fd25ed68d0dbeee268f82914145" ,
"http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg" ,
false ,
} ,
} ,
{ "7b226c616e6775616765223a2022656e222c2022666565223a207b22555344223a207b22616d6f756e74223a20302e30312c202261646472657373223a2022624d486d5a4b5a6250713662504245514663384d5870694468463966374d56784d52227d7d2c2022736f7572636573223a207b226c6272795f73645f68617368223a2022326264386439646431613231386337663536373137653533666135313065666435613863303839656431663236373561306638643062356238626233633165643338336362396633616562396238393137383937363133303532393339373961227d2c20226465736372697074696f6e223a2022636c6f756473222c20226c6963656e7365223a2022637265617469766520636f6d6d6f6e73222c2022617574686f72223a202268747470733a2f2f7777772e76696465657a792e636f6d2f636c6f7564732f323637362d6461726b2d73746f726d2d636c6f7564732d726f79616c74792d667265652d68642d73746f636b2d766964656f222c20226e736677223a2066616c73652c20227469746c65223a2022636c6f756473222c2022636f6e74656e742d74797065223a2022766964656f2f6d7034222c2022766572223a2022302e302e32227d" ,
claimResult { "0.0.2" ,
"https://www.videezy.com/clouds/2676-dark-storm-clouds-royalty-free-hd-stock-video" ,
"clouds" ,
"clouds" ,
"creative commons" ,
"" ,
0.01 ,
"USD" ,
"bMHmZKZbPq6bPBEQFc8MXpiDhF9f7MVxMR" ,
"video/mp4" ,
2019-04-07 06:29:12 +02:00
"language:en " ,
2018-11-09 18:10:58 +01:00
"2bd8d9dd1a218c7f56717e53fa510efd5a8c089ed1f2675a0f8d0b5b8bb3c1ed383cb9f3aeb9b891789761305293979a" ,
"" ,
false ,
} ,
} ,
{ "7b226c6963656e7365223a2022437265617469766520436f6d6d6f6e73204174747269627574696f6e20332e3020556e6974656420537461746573222c2022666565223a207b224c4243223a207b22616d6f756e74223a20312c202261646472657373223a20226256507157775966766a424859426f7575766b6e62514d58555a46764c644573354d227d7d2c2022766572223a2022302e302e32222c20226465736372697074696f6e223a20227a222c20226c616e6775616765223a2022656e222c2022617574686f72223a202279222c20227469746c65223a202278222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022376332316565323337333234653561353061333432353632306665366363343030643363636363303535313938363763646131623963313061393737313934653331323030343134643837313436626666343730626162376637643735343738227d2c20226e736677223a2066616c73652c20226c6963656e73655f75726c223a202268747470733a2f2f6372656174697665636f6d6d6f6e732e6f72672f6c6963656e7365732f62792f332e302f75732f6c6567616c636f6465222c2022636f6e74656e742d74797065223a2022746578742f706c61696e227d" ,
claimResult { "0.0.2" ,
"y" ,
"x" ,
"z" ,
"Creative Commons Attribution 3.0 United States" ,
"https://creativecommons.org/licenses/by/3.0/us/legalcode" ,
1 ,
"LBC" ,
"bVPqWwYfvjBHYBouuvknbQMXUZFvLdEs5M" ,
"text/plain" ,
2019-04-07 06:29:12 +02:00
"language:en " ,
2018-11-09 18:10:58 +01:00
"7c21ee237324e5a50a3425620fe6cc400d3cccc05519867cda1b9c10a977194e31200414d87146bff470bab7f7d75478" ,
"" ,
false ,
} ,
} ,
{ "7b22666565223a207b22555344223a207b22616d6f756e74223a20302e342c202261646472657373223a202262485365334b417674565352346d365331317a6475754639584874777363446a6f45227d7d2c2022766572223a2022302e302e33222c20226c6963656e7365223a2022437265617469766520436f6d6d6f6e73204174747269627574696f6e20332e3020556e6974656420537461746573222c20226c616e6775616765223a2022656e222c20227469746c65223a2022526561647920506c61796572204f6e652028417564696f626f6f6b2031206f66203229222c2022617574686f72223a202245726e65737420436c696e65222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022333430653164646130653834313463323166616662623166323866326338623338343832316665306431653261373134336134383130353435653634653236613431303530343264346434376463393735346236313865636466653064313931227d2c20226e736677223a2066616c73652c2022636f6e74656e745f74797065223a2022617564696f2f6d706567222c20226c6963656e73655f75726c223a202268747470733a2f2f6372656174697665636f6d6d6f6e732e6f72672f6c6963656e7365732f62792f332e302f75732f6c6567616c636f6465222c20227468756d626e61696c223a2022687474703a2f2f692e696d6775722e636f6d2f6c794b45485a632e6a7067222c20226465736372697074696f6e223a2022496e20746865207965617220323034342c2074686520776f726c64206973206772697070656420627920616e20656e65726779206372697369732063617573696e67207769646573707265616420736f6369616c2070726f626c656d7320616e642065636f6e6f6d696320737461676e6174696f6e2e20546865207072696d6172792065736361706520666f72206d6f73742070656f706c6520697320746865204f415349532c2061207669727475616c20756e6976657273652c20616363657373656420776974682061207669736f7220616e642068617074696320676c6f7665732e2049742066756e6374696f6e7320626f746820617320616e204d4d4f52504720616e642061732061207669727475616c20736f63696574792c2077697468206974732063757272656e6379206265696e6720746865206d6f737420737461626c652063757272656e637920696e2074686520776f726c642e204974207761732063726561746564206279204a616d65732048616c6c696461792c2077686f73652077696c6c206c656674206120736572696573206f6620636c75657320746f776172647320616e20456173746572204567672077697468696e20746865204f41534953207468617420776f756c64206772616e742077686f6576657220666f756e6420697420626f74682068697320666f7274756e6520616e6420636f6e74726f6c206f6620746865204f4153495320697473656c662e205468697320686173206c656420746f20616e20696e74656e736520696e74657265737420696e20616c6c2061737065637473206f662038307320706f702063756c747572652c2077686963682048616c6c69646179206d61646520636c65617220776f756c6420626520657373656e7469616c20746f2066696e64696e6720686973206567672e227d" ,
claimResult { "0.0.3" ,
"Ernest Cline" ,
"Ready Player One (Audiobook 1 of 2)" ,
"In the year 2044, the world is gripped by an energy crisis causing widespread social problems and economic stagnation. The primary escape for most people is the OASIS, a virtual universe, accessed with a visor and haptic gloves. It functions both as an MMORPG and as a virtual society, with its currency being the most stable currency in the world. It was created by James Halliday, whose will left a series of clues towards an Easter Egg within the OASIS that would grant whoever found it both his fortune and control of the OASIS itself. This has led to an intense interest in all aspects of 80s pop culture, which Halliday made clear would be essential to finding his egg." ,
"Creative Commons Attribution 3.0 United States" ,
"https://creativecommons.org/licenses/by/3.0/us/legalcode" ,
0.4 ,
"USD" ,
"bHSe3KAvtVSR4m6S11zduuF9XHtwscDjoE" ,
"audio/mpeg" ,
2019-04-07 06:29:12 +02:00
"language:en " ,
2018-11-09 18:10:58 +01:00
"340e1dda0e8414c21fafbb1f28f2c8b384821fe0d1e2a7143a4810545e64e26a4105042d4d47dc9754b618ecdfe0d191" ,
"http://i.imgur.com/lyKEHZc.jpg" ,
false ,
} ,
} ,
{ "7b22666565223a207b224c4243223a207b22616d6f756e74223a20312c202261646472657373223a202262525478744355706a3654764a48675763527347634861467972524c6b6b69586747227d7d2c2022766572223a2022302e302e33222c20226c6963656e7365223a2022436f707972696768742032303136206272617a7a657273222c20226c616e6775616765223a2022656e222c20227469746c65223a2022686f7420706f726e222c2022617574686f72223a20226272617a7a657273222c2022736f7572636573223a207b226c6272795f73645f68617368223a2022666330646163356366633532363335343936336666313736396636653733396334653432613037393034323066666162396661336236343031653933616535613035313565666639363066386339633237323930376564613666636261323534227d2c20226e736677223a20747275652c2022636f6e74656e745f74797065223a2022766964656f2f6d7034222c20226465736372697074696f6e223a2022686f7420706f726e5c6e6272617a7a657273227d" ,
claimResult { "0.0.3" ,
"brazzers" ,
"hot porn" ,
"hot porn\nbrazzers" ,
"Copyright 2016 brazzers" ,
"" ,
1 ,
"LBC" ,
"bRTxtCUpj6TvJHgWcRsGcHaFyrRLkkiXgG" ,
"video/mp4" ,
2019-04-07 06:29:12 +02:00
"language:en " ,
2018-11-09 18:10:58 +01:00
"fc0dac5cfc526354963ff1769f6e739c4e42a0790420ffab9fa3b6401e93ae5a0515eff960f8c9c272907eda6fcba254" ,
"" ,
true ,
} ,
} ,
}
2018-11-09 22:39:27 +01:00
func TestBadMigrationFromJSON ( t * testing . T ) {
for _ , hexStr := range badJsonVersionTests {
valueBytes , err := hex . DecodeString ( hexStr )
if err != nil {
t . Error ( err )
}
_ , err = DecodeClaimBytes ( valueBytes , "lbrycrd_main" )
if err == nil {
t . Error ( fmt . Sprintf ( "Decode error: The raw claim '%s' should have failed decoding." , hexStr ) )
}
}
}
2018-11-09 18:10:58 +01:00
func TestMigrationFromJSON ( t * testing . T ) {
for _ , pair := range jsonVersionTests {
valueBytes , err := hex . DecodeString ( pair . ValueAsHex )
if err != nil {
t . Error ( err )
}
helper , err := DecodeClaimBytes ( valueBytes , "lbrycrd_main" )
if err != nil {
t . Error ( "Decode error: " , err )
}
2019-04-07 06:29:12 +02:00
if helper . Claim . GetStream ( ) . GetAuthor ( ) != pair . Claim . Author {
t . Error ( "Author mismatch: expected" , pair . Claim . Author , "got" , helper . Claim . GetStream ( ) . GetAuthor ( ) )
2018-11-09 18:10:58 +01:00
}
2019-04-22 05:06:48 +02:00
if helper . Claim . GetTitle ( ) != pair . Claim . Title {
t . Error ( "Title mismatch: expected" , pair . Claim . Title , "got '" , helper . Claim . GetTitle ( ) , "'" )
2018-11-09 18:10:58 +01:00
}
2019-04-22 05:06:48 +02:00
if helper . Claim . GetDescription ( ) != pair . Claim . Description {
t . Error ( "Description mismatch: expected" , pair . Claim . Description , "got '" , helper . Claim . GetDescription ( ) , "'" )
2018-11-09 18:10:58 +01:00
}
2019-04-07 06:29:12 +02:00
if helper . Claim . GetStream ( ) . GetLicense ( ) != pair . Claim . License {
t . Error ( "License mismatch: expected" , pair . Claim . License , "got" , helper . Claim . GetStream ( ) . GetLicense ( ) )
2018-11-09 18:10:58 +01:00
}
2019-04-07 06:29:12 +02:00
if helper . Claim . GetStream ( ) . GetLicenseUrl ( ) != pair . Claim . LicenseURL {
t . Error ( "LicenseURL mismatch: expected" , pair . Claim . LicenseURL , "got" , helper . Claim . GetStream ( ) . GetLicenseUrl ( ) )
2018-11-09 18:10:58 +01:00
}
2019-04-07 06:29:12 +02:00
if helper . Claim . GetStream ( ) . GetFee ( ) . GetAmount ( ) != uint64 ( pair . Claim . FeeAmount * 100000000 ) {
t . Error ( "Fee Amount mismatch: expected" , pair . Claim . FeeAmount , "got" , helper . Claim . GetStream ( ) . GetFee ( ) . GetAmount ( ) )
2018-11-09 18:10:58 +01:00
}
2019-04-07 06:29:12 +02:00
if helper . Claim . GetStream ( ) . GetFee ( ) . GetCurrency ( ) . String ( ) != pair . Claim . FeeCurrency {
t . Error ( "Fee Currency mismatch: expected" , pair . Claim . FeeCurrency , "got" , helper . Claim . GetStream ( ) . GetFee ( ) . GetCurrency ( ) )
2018-11-09 18:10:58 +01:00
}
2019-04-07 06:29:12 +02:00
hexaddress := base58 . Encode ( helper . Claim . GetStream ( ) . GetFee ( ) . GetAddress ( ) )
2018-11-09 18:10:58 +01:00
if hexaddress != pair . Claim . FeeAddress {
t . Error ( "Fee Address mismatch: expected" , pair . Claim . FeeAddress , "got" , hexaddress )
}
2019-04-22 05:06:48 +02:00
if helper . Claim . GetStream ( ) . GetSource ( ) . GetMediaType ( ) != pair . Claim . ContentType {
t . Error ( "ContentType mismatch: expected" , pair . Claim . ContentType , "got" , helper . Claim . GetStream ( ) . GetSource ( ) . GetMediaType ( ) )
2018-11-09 18:10:58 +01:00
}
2019-04-22 05:06:48 +02:00
if helper . Claim . GetLanguages ( ) [ 0 ] . String ( ) != pair . Claim . Language {
t . Error ( "Language mismatch: expected " , pair . Claim . Language , " got " , helper . Claim . GetLanguages ( ) [ 0 ] . String ( ) )
2018-11-09 18:10:58 +01:00
}
2019-04-22 05:06:48 +02:00
content := hex . EncodeToString ( helper . Claim . GetStream ( ) . GetSource ( ) . GetSdHash ( ) )
2018-11-09 18:10:58 +01:00
if content != pair . Claim . LbrySDHash {
t . Error ( "Source mismatch: expected" , pair . Claim . LbrySDHash , "got" , content )
}
}
}
2019-04-07 06:29:12 +02:00
func TestMigrationFromV1YTSync ( t * testing . T ) {
claimHex := "080110011aee04080112a604080410011a2b4865726520617265203520526561736f6e73204920e29da4efb88f204e657874636c6f7564207c20544c4722920346696e64206f7574206d6f72652061626f7574204e657874636c6f75643a2068747470733a2f2f6e657874636c6f75642e636f6d2f0a0a596f752063616e2066696e64206d65206f6e20746865736520736f6369616c733a0a202a20466f72756d733a2068747470733a2f2f666f72756d2e6865617679656c656d656e742e696f2f0a202a20506f64636173743a2068747470733a2f2f6f6666746f706963616c2e6e65740a202a2050617472656f6e3a2068747470733a2f2f70617472656f6e2e636f6d2f7468656c696e757867616d65720a202a204d657263683a2068747470733a2f2f746565737072696e672e636f6d2f73746f7265732f6f6666696369616c2d6c696e75782d67616d65720a202a205477697463683a2068747470733a2f2f7477697463682e74762f786f6e64616b0a202a20547769747465723a2068747470733a2f2f747769747465722e636f6d2f7468656c696e757867616d65720a0a2e2e2e0a68747470733a2f2f7777772e796f75747562652e636f6d2f77617463683f763d4672546442434f535f66632a0f546865204c696e75782047616d6572321c436f7079726967687465642028636f6e7461637420617574686f722938004a2968747470733a2f2f6265726b2e6e696e6a612f7468756d626e61696c732f4672546442434f535f666352005a001a41080110011a30040e8ac6e89c061f982528c23ad33829fd7146435bf7a4cc22f0bff70c4fe0b91fd36da9a375e3e1c171db825bf5d1f32209766964656f2f6d70342a5c080110031a4062b2dd4c45e364030fbfad1a6fefff695ebf20ea33a5381b947753e2a0ca359989a5cc7d15e5392a0d354c0b68498382b2701b22c03beb8dcb91089031b871e72214feb61536c007cdf4faeeaab4876cb397feaf6b51"
claim , err := DecodeClaimHex ( claimHex , "lbrycrd_main" )
if err != nil {
t . Error ( err )
}
2020-10-28 06:36:49 +01:00
assert . Assert ( t , claim . Claim . GetTitle ( ) == "Here are 5 Reasons I ❤️ Nextcloud | TLG" )
assert . Assert ( t , claim . 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" )
2019-04-07 06:29:12 +02:00
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])
2019-04-22 05:06:48 +02:00
assert . Assert ( t , claim . GetStream ( ) . GetSource ( ) . GetMediaType ( ) == "video/mp4" )
2020-10-28 06:36:49 +01:00
assert . Assert ( t , claim . Claim . GetThumbnail ( ) . GetUrl ( ) == "https://berk.ninja/thumbnails/FrTdBCOS_fc" )
2019-04-07 06:29:12 +02:00
sdHashBytes , err := hex . DecodeString ( "040e8ac6e89c061f982528c23ad33829fd7146435bf7a4cc22f0bff70c4fe0b91fd36da9a375e3e1c171db825bf5d1f3" )
if err != nil {
t . Error ( err )
}
2019-04-22 05:06:48 +02:00
assert . Assert ( t , bytes . Equal ( claim . GetStream ( ) . GetSource ( ) . GetSdHash ( ) , sdHashBytes ) )
2019-04-07 06:29:12 +02:00
channelHex := "08011002225e0801100322583056301006072a8648ce3d020106052b8104000a034200043878b1edd4a1373149909ef03f4339f6da9c2bd2214c040fd2e530463ffe66098eca14fc70b50ff3aefd106049a815f595ed5a13eda7419ad78d9ed7ae473f17"
channel , err := DecodeClaimHex ( channelHex , "lbrycrd_main" )
if err != nil {
t . Error ( err )
}
pubKeyBytes , err := hex . DecodeString ( "3056301006072a8648ce3d020106052b8104000a034200043878b1edd4a1373149909ef03f4339f6da9c2bd2214c040fd2e530463ffe66098eca14fc70b50ff3aefd106049a815f595ed5a13eda7419ad78d9ed7ae473f17" )
if err != nil {
t . Error ( err )
}
2020-10-28 06:36:49 +01:00
assert . Assert ( t , bytes . Equal ( pubKeyBytes , channel . Claim . GetChannel ( ) . GetPublicKey ( ) ) )
2019-04-07 06:29:12 +02:00
}
func TestMigrationFromV1UnsignedWithFee ( t * testing . T ) {
claimHex := "080110011ad6010801127c080410011a08727067206d69646922046d6964692a08727067206d696469322e437265617469766520436f6d6d6f6e73204174747269627574696f6e20342e3020496e7465726e6174696f6e616c38004224080110011a19553f00bc139bbf40de425f94d51fffb34c1bea6d9171cd374c25000070414a0052005a001a54080110011a301f41eb0312aa7e8a5ce49349bc77d811da975833719d751523b19f123fc3d528d6a94e3446ccddb7b9329f27a9cad7e3221c6170706c69636174696f6e2f782d7a69702d636f6d70726573736564"
claim , err := DecodeClaimHex ( claimHex , "lbrycrd_main" )
if err != nil {
t . Error ( err )
}
2020-10-28 06:36:49 +01:00
assert . Assert ( t , claim . Claim . GetTitle ( ) == "rpg midi" )
assert . Assert ( t , claim . Claim . GetDescription ( ) == "midi" )
2019-04-07 06:29:12 +02:00
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")
2019-04-22 05:06:48 +02:00
assert . Assert ( t , claim . GetStream ( ) . GetSource ( ) . GetMediaType ( ) == "application/x-zip-compressed" )
2019-04-07 06:29:12 +02:00
sdHashBytes , err := hex . DecodeString ( "1f41eb0312aa7e8a5ce49349bc77d811da975833719d751523b19f123fc3d528d6a94e3446ccddb7b9329f27a9cad7e3" )
if err != nil {
t . Error ( err )
}
2019-04-22 05:06:48 +02:00
assert . Assert ( t , bytes . Equal ( claim . GetStream ( ) . GetSource ( ) . GetSdHash ( ) , sdHashBytes ) )
2019-04-07 06:29:12 +02:00
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 )
assert . Assert ( t , claim . GetStream ( ) . GetFee ( ) . GetCurrency ( ) . String ( ) == "LBC" )
}