mirror of https://codeberg.org/pzp/pzp-sync.git
rename identity to account
This commit is contained in:
parent
ffb8860fb8
commit
f6f16bdd47
|
@ -41,7 +41,7 @@
|
|||
"prettier": "^2.6.2",
|
||||
"pretty-quick": "^3.1.3",
|
||||
"rimraf": "^4.4.0",
|
||||
"secret-stack": "ssbc/secret-stack#bare-mode",
|
||||
"secret-stack": "~7.1.0",
|
||||
"secret-handshake-ext": "^0.0.8",
|
||||
"ssb-box": "^1.0.1"
|
||||
},
|
||||
|
|
|
@ -7,48 +7,48 @@ const { createPeer } = require('./util')
|
|||
const aliceKeypair = Keypair.generate('ed25519', 'alice')
|
||||
const bobKeys = Keypair.generate('ed25519', 'bob')
|
||||
|
||||
function getIdentity(iter) {
|
||||
function getAccount(iter) {
|
||||
return [...iter]
|
||||
.filter((msg) => msg.metadata.identity === 'self' && msg.data)
|
||||
.map((msg) => msg.data.add)
|
||||
.filter((msg) => msg.metadata.account === 'self' && msg.data)
|
||||
.map((msg) => msg.data.add.key.bytes)
|
||||
}
|
||||
|
||||
test('sync an identity tangle', async (t) => {
|
||||
test('sync an account tangle', async (t) => {
|
||||
const alice = createPeer({ name: 'alice', keypair: aliceKeypair })
|
||||
const bob = createPeer({ name: 'bob', keypair: bobKeys })
|
||||
|
||||
await alice.db.loaded()
|
||||
await bob.db.loaded()
|
||||
|
||||
// Alice's identity tangle
|
||||
// Alice's account tangle
|
||||
await alice.db.loaded()
|
||||
const aliceID = await p(alice.db.identity.create)({
|
||||
const aliceID = await p(alice.db.account.create)({
|
||||
domain: 'account',
|
||||
_nonce: 'alice',
|
||||
})
|
||||
|
||||
const aliceKeypair1 = Keypair.generate('ed25519', 'alice1')
|
||||
await p(alice.db.identity.add)({
|
||||
identity: aliceID,
|
||||
await p(alice.db.account.add)({
|
||||
account: aliceID,
|
||||
keypair: aliceKeypair1,
|
||||
})
|
||||
|
||||
const aliceKeypair2 = Keypair.generate('ed25519', 'alice2')
|
||||
await p(alice.db.identity.add)({
|
||||
identity: aliceID,
|
||||
await p(alice.db.account.add)({
|
||||
account: aliceID,
|
||||
keypair: aliceKeypair2,
|
||||
})
|
||||
|
||||
assert.deepEqual(
|
||||
getIdentity(alice.db.msgs()),
|
||||
getAccount(alice.db.msgs()),
|
||||
[aliceKeypair.public, aliceKeypair1.public, aliceKeypair2.public],
|
||||
'alice has her identity tangle'
|
||||
'alice has her account tangle'
|
||||
)
|
||||
|
||||
assert.deepEqual(
|
||||
getIdentity(bob.db.msgs()),
|
||||
getAccount(bob.db.msgs()),
|
||||
[],
|
||||
"bob doesn't have alice's identity tangle"
|
||||
"bob doesn't have alice's account tangle"
|
||||
)
|
||||
|
||||
bob.tangleSync.setGoal(aliceID, 'all')
|
||||
|
@ -62,9 +62,9 @@ test('sync an identity tangle', async (t) => {
|
|||
assert('tangleSync!')
|
||||
|
||||
assert.deepEqual(
|
||||
getIdentity(bob.db.msgs()),
|
||||
getAccount(bob.db.msgs()),
|
||||
[aliceKeypair.public, aliceKeypair1.public, aliceKeypair2.public],
|
||||
"bob has alice's identity tangle"
|
||||
"bob has alice's account tangle"
|
||||
)
|
||||
|
||||
await p(remoteAlice.close)(true)
|
|
@ -14,7 +14,7 @@ test('sync a feed with goal=all', async (t) => {
|
|||
await alice.db.loaded()
|
||||
await bob.db.loaded()
|
||||
|
||||
const carolID = await p(alice.db.identity.create)({
|
||||
const carolID = await p(alice.db.account.create)({
|
||||
keypair: carolKeypair,
|
||||
domain: 'account',
|
||||
_nonce: 'carol',
|
||||
|
@ -27,7 +27,7 @@ test('sync a feed with goal=all', async (t) => {
|
|||
const carolMsgs = []
|
||||
for (let i = 1; i <= 10; i++) {
|
||||
const rec = await p(alice.db.feed.publish)({
|
||||
identity: carolID,
|
||||
account: carolID,
|
||||
domain: 'post',
|
||||
data: { text: 'm' + i },
|
||||
keypair: carolKeypair,
|
||||
|
@ -46,7 +46,7 @@ test('sync a feed with goal=all', async (t) => {
|
|||
|
||||
{
|
||||
const arr = [...bob.db.msgs()]
|
||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||
.filter((msg) => msg.metadata.account === carolID && msg.data)
|
||||
.map((msg) => msg.data.text)
|
||||
assert.deepEqual(
|
||||
arr,
|
||||
|
@ -67,7 +67,7 @@ test('sync a feed with goal=all', async (t) => {
|
|||
|
||||
{
|
||||
const arr = [...bob.db.msgs()]
|
||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||
.filter((msg) => msg.metadata.account === carolID && msg.data)
|
||||
.map((msg) => msg.data.text)
|
||||
assert.deepEqual(
|
||||
arr,
|
||||
|
@ -88,7 +88,7 @@ test('sync a feed with goal=newest', async (t) => {
|
|||
await alice.db.loaded()
|
||||
await bob.db.loaded()
|
||||
|
||||
const carolID = await p(alice.db.identity.create)({
|
||||
const carolID = await p(alice.db.account.create)({
|
||||
keypair: carolKeypair,
|
||||
domain: 'account',
|
||||
_nonce: 'carol',
|
||||
|
@ -101,7 +101,7 @@ test('sync a feed with goal=newest', async (t) => {
|
|||
const carolMsgs = []
|
||||
for (let i = 1; i <= 10; i++) {
|
||||
const rec = await p(alice.db.feed.publish)({
|
||||
identity: carolID,
|
||||
account: carolID,
|
||||
domain: 'post',
|
||||
data: { text: 'm' + i },
|
||||
keypair: carolKeypair,
|
||||
|
@ -120,7 +120,7 @@ test('sync a feed with goal=newest', async (t) => {
|
|||
|
||||
{
|
||||
const arr = [...bob.db.msgs()]
|
||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||
.filter((msg) => msg.metadata.account === carolID && msg.data)
|
||||
.map((msg) => msg.data.text)
|
||||
assert.deepEqual(
|
||||
arr,
|
||||
|
@ -141,7 +141,7 @@ test('sync a feed with goal=newest', async (t) => {
|
|||
|
||||
{
|
||||
const arr = [...bob.db.msgs()]
|
||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||
.filter((msg) => msg.metadata.account === carolID && msg.data)
|
||||
.map((msg) => msg.data.text)
|
||||
assert.deepEqual(
|
||||
arr,
|
||||
|
@ -162,7 +162,7 @@ test('sync a feed with goal=newest but too far behind', async (t) => {
|
|||
await alice.db.loaded()
|
||||
await bob.db.loaded()
|
||||
|
||||
const carolID = await p(alice.db.identity.create)({
|
||||
const carolID = await p(alice.db.account.create)({
|
||||
keypair: carolKeypair,
|
||||
domain: 'account',
|
||||
_nonce: 'carol',
|
||||
|
@ -175,7 +175,7 @@ test('sync a feed with goal=newest but too far behind', async (t) => {
|
|||
const carolMsgs = []
|
||||
for (let i = 1; i <= 10; i++) {
|
||||
const rec = await p(alice.db.feed.publish)({
|
||||
identity: carolID,
|
||||
account: carolID,
|
||||
domain: 'post',
|
||||
data: { text: 'm' + i },
|
||||
keypair: carolKeypair,
|
||||
|
@ -190,7 +190,7 @@ test('sync a feed with goal=newest but too far behind', async (t) => {
|
|||
await algo.pruneNewest(carolPostsRootHash, 5)
|
||||
{
|
||||
const arr = [...alice.db.msgs()]
|
||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||
.filter((msg) => msg.metadata.account === carolID && msg.data)
|
||||
.map((msg) => msg.data.text)
|
||||
assert.deepEqual(
|
||||
arr,
|
||||
|
@ -206,7 +206,7 @@ test('sync a feed with goal=newest but too far behind', async (t) => {
|
|||
|
||||
{
|
||||
const arr = [...bob.db.msgs()]
|
||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||
.filter((msg) => msg.metadata.account === carolID && msg.data)
|
||||
.map((msg) => msg.data.text)
|
||||
assert.deepEqual(arr, ['m1', 'm2'], 'bob has msgs 1..2 from carol')
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ test('sync a feed with goal=newest but too far behind', async (t) => {
|
|||
|
||||
{
|
||||
const arr = [...bob.db.msgs()]
|
||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||
.filter((msg) => msg.metadata.account === carolID && msg.data)
|
||||
.map((msg) => msg.data.text)
|
||||
assert.deepEqual(
|
||||
arr,
|
||||
|
|
|
@ -53,21 +53,21 @@ test('sync a thread where both peers have portions', async (t) => {
|
|||
const bob = createPeer({ name: 'bob' })
|
||||
|
||||
await alice.db.loaded()
|
||||
const aliceID = await p(alice.db.identity.create)({
|
||||
const aliceID = await p(alice.db.account.create)({
|
||||
domain: 'account',
|
||||
_nonce: 'alice',
|
||||
})
|
||||
const aliceIDMsg = alice.db.get(aliceID)
|
||||
|
||||
await bob.db.loaded()
|
||||
const bobID = await p(bob.db.identity.create)({
|
||||
const bobID = await p(bob.db.account.create)({
|
||||
domain: 'account',
|
||||
_nonce: 'bob',
|
||||
})
|
||||
const bobIDMsg = bob.db.get(bobID)
|
||||
|
||||
// Alice created Carol
|
||||
const carolID = await p(alice.db.identity.create)({
|
||||
const carolID = await p(alice.db.account.create)({
|
||||
domain: 'account',
|
||||
keypair: carolKeypair,
|
||||
_nonce: 'carol',
|
||||
|
@ -75,7 +75,7 @@ test('sync a thread where both peers have portions', async (t) => {
|
|||
const carolIDMsg = alice.db.get(carolID)
|
||||
|
||||
// Alice created Dave
|
||||
const daveID = await p(alice.db.identity.create)({
|
||||
const daveID = await p(alice.db.account.create)({
|
||||
domain: 'account',
|
||||
keypair: daveKeypair,
|
||||
_nonce: 'dave',
|
||||
|
@ -91,7 +91,7 @@ test('sync a thread where both peers have portions', async (t) => {
|
|||
await p(bob.db.add)(daveIDMsg, daveID)
|
||||
|
||||
const startA = await p(alice.db.feed.publish)({
|
||||
identity: aliceID,
|
||||
account: aliceID,
|
||||
domain: 'post',
|
||||
data: { text: 'A' },
|
||||
})
|
||||
|
@ -102,14 +102,14 @@ test('sync a thread where both peers have portions', async (t) => {
|
|||
await p(bob.db.add)(startA.msg, rootHashA)
|
||||
|
||||
const replyB1 = await p(bob.db.feed.publish)({
|
||||
identity: bobID,
|
||||
account: bobID,
|
||||
domain: 'post',
|
||||
data: { text: 'B1' },
|
||||
tangles: [startA.hash],
|
||||
})
|
||||
|
||||
const replyB2 = await p(bob.db.feed.publish)({
|
||||
identity: bobID,
|
||||
account: bobID,
|
||||
domain: 'post',
|
||||
data: { text: 'B2' },
|
||||
tangles: [startA.hash],
|
||||
|
@ -122,7 +122,7 @@ test('sync a thread where both peers have portions', async (t) => {
|
|||
await p(alice.db.add)(replyB2.msg, rootHashB)
|
||||
|
||||
const replyC1 = await p(alice.db.feed.publish)({
|
||||
identity: carolID,
|
||||
account: carolID,
|
||||
domain: 'post',
|
||||
data: { text: 'C1' },
|
||||
tangles: [startA.hash],
|
||||
|
@ -130,7 +130,7 @@ test('sync a thread where both peers have portions', async (t) => {
|
|||
})
|
||||
|
||||
const replyD1 = await p(bob.db.feed.publish)({
|
||||
identity: daveID,
|
||||
account: daveID,
|
||||
domain: 'post',
|
||||
data: { text: 'D1' },
|
||||
tangles: [startA.hash],
|
||||
|
@ -181,14 +181,14 @@ test('sync a thread where initiator does not have the root', async (t) => {
|
|||
const bob = createPeer({ name: 'bob' })
|
||||
|
||||
await alice.db.loaded()
|
||||
const aliceID = await p(alice.db.identity.create)({
|
||||
const aliceID = await p(alice.db.account.create)({
|
||||
domain: 'account',
|
||||
_nonce: 'alice',
|
||||
})
|
||||
const aliceIDMsg = alice.db.get(aliceID)
|
||||
|
||||
await bob.db.loaded()
|
||||
const bobID = await p(bob.db.identity.create)({
|
||||
const bobID = await p(bob.db.account.create)({
|
||||
domain: 'account',
|
||||
_nonce: 'bob',
|
||||
})
|
||||
|
@ -201,20 +201,20 @@ test('sync a thread where initiator does not have the root', async (t) => {
|
|||
await p(bob.db.add)(aliceIDMsg, aliceID)
|
||||
|
||||
const rootA = await p(alice.db.feed.publish)({
|
||||
identity: aliceID,
|
||||
account: aliceID,
|
||||
domain: 'post',
|
||||
data: { text: 'A' },
|
||||
})
|
||||
|
||||
const replyA1 = await p(alice.db.feed.publish)({
|
||||
identity: aliceID,
|
||||
account: aliceID,
|
||||
domain: 'post',
|
||||
data: { text: 'A1' },
|
||||
tangles: [rootA.hash],
|
||||
})
|
||||
|
||||
const replyA2 = await p(alice.db.feed.publish)({
|
||||
identity: aliceID,
|
||||
account: aliceID,
|
||||
domain: 'post',
|
||||
data: { text: 'A2' },
|
||||
tangles: [rootA.hash],
|
||||
|
@ -255,14 +255,14 @@ test('sync a thread where receiver does not have the root', async (t) => {
|
|||
const bob = createPeer({ name: 'bob' })
|
||||
|
||||
await alice.db.loaded()
|
||||
const aliceID = await p(alice.db.identity.create)({
|
||||
const aliceID = await p(alice.db.account.create)({
|
||||
domain: 'account',
|
||||
_nonce: 'alice',
|
||||
})
|
||||
const aliceIDMsg = alice.db.get(aliceID)
|
||||
|
||||
await bob.db.loaded()
|
||||
const bobID = await p(bob.db.identity.create)({
|
||||
const bobID = await p(bob.db.account.create)({
|
||||
domain: 'account',
|
||||
_nonce: 'bob',
|
||||
})
|
||||
|
@ -275,20 +275,20 @@ test('sync a thread where receiver does not have the root', async (t) => {
|
|||
await p(bob.db.add)(aliceIDMsg, aliceID)
|
||||
|
||||
const rootA = await p(alice.db.feed.publish)({
|
||||
identity: aliceID,
|
||||
account: aliceID,
|
||||
domain: 'post',
|
||||
data: { text: 'A' },
|
||||
})
|
||||
|
||||
const replyA1 = await p(alice.db.feed.publish)({
|
||||
identity: aliceID,
|
||||
account: aliceID,
|
||||
domain: 'post',
|
||||
data: { text: 'A1' },
|
||||
tangles: [rootA.hash],
|
||||
})
|
||||
|
||||
const replyA2 = await p(alice.db.feed.publish)({
|
||||
identity: aliceID,
|
||||
account: aliceID,
|
||||
domain: 'post',
|
||||
data: { text: 'A2' },
|
||||
tangles: [rootA.hash],
|
||||
|
@ -328,14 +328,14 @@ test('sync a thread with reactions too', async (t) => {
|
|||
const bob = createPeer({ name: 'bob' })
|
||||
|
||||
await alice.db.loaded()
|
||||
const aliceID = await p(alice.db.identity.create)({
|
||||
const aliceID = await p(alice.db.account.create)({
|
||||
domain: 'account',
|
||||
_nonce: 'alice',
|
||||
})
|
||||
const aliceIDMsg = alice.db.get(aliceID)
|
||||
|
||||
await bob.db.loaded()
|
||||
const bobID = await p(bob.db.identity.create)({
|
||||
const bobID = await p(bob.db.account.create)({
|
||||
domain: 'account',
|
||||
_nonce: 'bob',
|
||||
})
|
||||
|
@ -348,27 +348,27 @@ test('sync a thread with reactions too', async (t) => {
|
|||
await p(bob.db.add)(aliceIDMsg, aliceID)
|
||||
|
||||
const rootA = await p(alice.db.feed.publish)({
|
||||
identity: aliceID,
|
||||
account: aliceID,
|
||||
domain: 'post',
|
||||
data: { text: 'A' },
|
||||
})
|
||||
|
||||
const replyA1 = await p(alice.db.feed.publish)({
|
||||
identity: aliceID,
|
||||
account: aliceID,
|
||||
domain: 'post',
|
||||
data: { text: 'A1' },
|
||||
tangles: [rootA.hash],
|
||||
})
|
||||
|
||||
const replyA2 = await p(alice.db.feed.publish)({
|
||||
identity: aliceID,
|
||||
account: aliceID,
|
||||
domain: 'post',
|
||||
data: { text: 'A2' },
|
||||
tangles: [rootA.hash],
|
||||
})
|
||||
|
||||
const reactionA3 = await p(alice.db.feed.publish)({
|
||||
identity: aliceID,
|
||||
account: aliceID,
|
||||
domain: 'reaction',
|
||||
data: { text: 'yes', link: replyA1.hash },
|
||||
tangles: [rootA.hash, replyA1.hash],
|
||||
|
|
Loading…
Reference in New Issue