Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
a77d62b8
Commit
a77d62b8
authored
2 years ago
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Fix formatting
parent
53e94f01
No related branches found
No related tags found
2 merge requests
!60
Revert "Fail a test to be sure it works"
,
!32
Admin Commands
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
indexedDb/channels/implementation_test.go
+21
-14
21 additions, 14 deletions
indexedDb/channels/implementation_test.go
indexedDb/dm/implementation.go
+17
-19
17 additions, 19 deletions
indexedDb/dm/implementation.go
indexedDb/utils.go
+2
-2
2 additions, 2 deletions
indexedDb/utils.go
with
40 additions
and
35 deletions
indexedDb/channels/implementation_test.go
+
21
−
14
View file @
a77d62b8
...
...
@@ -206,7 +206,7 @@ func Test_wasmModel_JoinChannel_LeaveChannel(t *testing.T) {
if
c
!=
nil
{
cs
=
"_withCipher"
}
t
.
Run
(
fmt
.
Sprintf
(
"Test_wasmModel_JoinChannel_LeaveChannel
%s"
,
cs
)
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"Test_wasmModel_JoinChannel_LeaveChannel
"
+
cs
,
func
(
t
*
testing
.
T
)
{
storage
.
GetLocalStorage
()
.
Clear
()
eventModel
,
err
:=
newWASMModel
(
"test"
,
c
,
dummyCallback
)
if
err
!=
nil
{
...
...
@@ -248,7 +248,8 @@ func Test_wasmModel_JoinChannel_LeaveChannel(t *testing.T) {
// Test UUID gets returned when different messages are added.
func
Test_wasmModel_UUIDTest
(
t
*
testing
.
T
)
{
cipher
,
err
:=
cryptoChannel
.
NewCipher
([]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
cipher
,
err
:=
cryptoChannel
.
NewCipher
(
[]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create cipher"
)
}
...
...
@@ -257,7 +258,7 @@ func Test_wasmModel_UUIDTest(t *testing.T) {
if
c
!=
nil
{
cs
=
"_withCipher"
}
t
.
Run
(
fmt
.
Sprintf
(
"Test_wasmModel_UUIDTest
%s"
,
cs
)
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"Test_wasmModel_UUIDTest
"
+
cs
,
func
(
t
*
testing
.
T
)
{
storage
.
GetLocalStorage
()
.
Clear
()
testString
:=
"testHello"
+
cs
eventModel
,
err
:=
newWASMModel
(
testString
,
c
,
dummyCallback
)
...
...
@@ -293,7 +294,8 @@ func Test_wasmModel_UUIDTest(t *testing.T) {
// Tests if the same message ID being sent always returns the same UUID.
func
Test_wasmModel_DuplicateReceives
(
t
*
testing
.
T
)
{
cipher
,
err
:=
cryptoChannel
.
NewCipher
([]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
cipher
,
err
:=
cryptoChannel
.
NewCipher
(
[]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create cipher"
)
}
...
...
@@ -302,7 +304,7 @@ func Test_wasmModel_DuplicateReceives(t *testing.T) {
if
c
!=
nil
{
cs
=
"_withCipher"
}
t
.
Run
(
fmt
.
Sprintf
(
"Test_wasmModel_DuplicateReceives
%s"
,
cs
)
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"Test_wasmModel_DuplicateReceives
"
+
cs
,
func
(
t
*
testing
.
T
)
{
storage
.
GetLocalStorage
()
.
Clear
()
testString
:=
"testHello"
eventModel
,
err
:=
newWASMModel
(
testString
,
c
,
dummyCallback
)
...
...
@@ -339,7 +341,8 @@ func Test_wasmModel_DuplicateReceives(t *testing.T) {
// Happy path: Inserts many messages, deletes some, and checks that the final
// result is as expected.
func
Test_wasmModel_deleteMsgByChannel
(
t
*
testing
.
T
)
{
cipher
,
err
:=
cryptoChannel
.
NewCipher
([]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
cipher
,
err
:=
cryptoChannel
.
NewCipher
(
[]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create cipher"
)
}
...
...
@@ -348,7 +351,7 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
if
c
!=
nil
{
cs
=
"_withCipher"
}
t
.
Run
(
fmt
.
Sprintf
(
"Test_wasmModel_deleteMsgByChannel
%s"
,
cs
)
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"Test_wasmModel_deleteMsgByChannel
"
+
cs
,
func
(
t
*
testing
.
T
)
{
storage
.
GetLocalStorage
()
.
Clear
()
testString
:=
"test_deleteMsgByChannel"
totalMessages
:=
10
...
...
@@ -372,10 +375,12 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
thisChannel
=
keepChannel
}
testMsgId
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
byte
(
i
)},
0
,
[]
byte
(
testStr
))
eventModel
.
ReceiveMessage
(
thisChannel
,
testMsgId
,
testStr
,
testStr
,
[]
byte
{
8
,
6
,
7
,
5
},
0
,
0
,
netTime
.
Now
(),
time
.
Second
,
rounds
.
Round
{
ID
:
id
.
Round
(
0
)},
0
,
channels
.
Sent
,
false
)
testMsgId
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
byte
(
i
)},
0
,
[]
byte
(
testStr
))
eventModel
.
ReceiveMessage
(
thisChannel
,
testMsgId
,
testStr
,
testStr
,
[]
byte
{
8
,
6
,
7
,
5
},
0
,
0
,
netTime
.
Now
(),
time
.
Second
,
rounds
.
Round
{
ID
:
id
.
Round
(
0
)},
0
,
channels
.
Sent
,
false
)
}
// Check pre-results
...
...
@@ -408,7 +413,8 @@ func Test_wasmModel_deleteMsgByChannel(t *testing.T) {
// This test is designed to prove the behavior of unique indexes.
// Inserts will not fail, they simply will not happen.
func
TestWasmModel_receiveHelper_UniqueIndex
(
t
*
testing
.
T
)
{
cipher
,
err
:=
cryptoChannel
.
NewCipher
([]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
cipher
,
err
:=
cryptoChannel
.
NewCipher
(
[]
byte
(
"testpass"
),
[]
byte
(
"testsalt"
),
128
,
csprng
.
NewSystemRNG
())
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create cipher"
)
}
...
...
@@ -417,7 +423,7 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
if
c
!=
nil
{
cs
=
"_withCipher"
}
t
.
Run
(
fmt
.
Sprintf
(
"TestWasmModel_receiveHelper_UniqueIndex
%s"
,
cs
)
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"TestWasmModel_receiveHelper_UniqueIndex
"
+
cs
,
func
(
t
*
testing
.
T
)
{
storage
.
GetLocalStorage
()
.
Clear
()
testString
:=
fmt
.
Sprintf
(
"test_receiveHelper_UniqueIndex_%d"
,
i
)
eventModel
,
err
:=
newWASMModel
(
testString
,
c
,
dummyCallback
)
...
...
@@ -465,7 +471,8 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) {
}
// Now insert a message with a different message ID from the first
testMsgId2
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
2
},
0
,
[]
byte
(
testString
))
testMsgId2
:=
message
.
DeriveChannelMessageID
(
&
id
.
ID
{
2
},
0
,
[]
byte
(
testString
))
testMsg
=
buildMessage
([]
byte
(
testString
),
testMsgId2
.
Bytes
(),
nil
,
testString
,
[]
byte
(
testString
),
[]
byte
{
8
,
6
,
7
,
5
},
0
,
0
,
netTime
.
Now
(),
time
.
Second
,
0
,
0
,
false
,
false
,
channels
.
Sent
)
...
...
This diff is collapsed.
Click to expand it.
indexedDb/dm/implementation.go
+
17
−
19
View file @
a77d62b8
...
...
@@ -96,8 +96,9 @@ func buildMessage(messageID, parentID []byte, text []byte,
}
func
(
w
*
wasmModel
)
Receive
(
messageID
message
.
ID
,
nickname
string
,
text
[]
byte
,
pubKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
mType
dm
.
MessageType
,
status
dm
.
Status
)
uint64
{
pubKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
mType
dm
.
MessageType
,
status
dm
.
Status
)
uint64
{
parentErr
:=
errors
.
New
(
"failed to Receive"
)
// If there is no extant Conversation, create one.
...
...
@@ -138,13 +139,13 @@ func (w *wasmModel) Receive(messageID message.ID, nickname string, text []byte,
}
func
(
w
*
wasmModel
)
ReceiveText
(
messageID
message
.
ID
,
nickname
,
text
string
,
pubKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
uint64
{
pubKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
uint64
{
parentErr
:=
errors
.
New
(
"failed to ReceiveText"
)
// If there is no extant Conversation, create one.
_
,
err
:=
indexedDb
.
Get
(
w
.
db
,
conversationStoreName
,
utils
.
CopyBytesToJS
(
pubKey
))
if
err
!=
nil
{
if
err
!=
nil
{
if
strings
.
Contains
(
err
.
Error
(),
indexedDb
.
ErrDoesNotExist
)
{
err
=
w
.
joinConversation
(
nickname
,
pubKey
,
dmToken
,
codeset
)
if
err
!=
nil
{
...
...
@@ -181,10 +182,9 @@ func (w *wasmModel) ReceiveText(messageID message.ID, nickname, text string,
return
uuid
}
func
(
w
*
wasmModel
)
ReceiveReply
(
messageID
message
.
ID
,
reactionTo
message
.
ID
,
nickname
,
text
string
,
pubKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
uint64
{
func
(
w
*
wasmModel
)
ReceiveReply
(
messageID
,
reactionTo
message
.
ID
,
nickname
,
text
string
,
pubKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
uint64
{
parentErr
:=
errors
.
New
(
"failed to ReceiveReply"
)
// If there is no extant Conversation, create one.
...
...
@@ -226,9 +226,9 @@ func (w *wasmModel) ReceiveReply(messageID message.ID, reactionTo message.ID,
return
uuid
}
func
(
w
*
wasmModel
)
ReceiveReaction
(
messageID
message
.
ID
,
reactionTo
message
.
ID
,
nickname
,
reaction
string
,
pubKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
uint64
{
func
(
w
*
wasmModel
)
ReceiveReaction
(
messageID
,
reactionTo
message
.
ID
,
nickname
,
reaction
string
,
pubKey
ed25519
.
PublicKey
,
dmToken
uint32
,
codeset
uint8
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
uint64
{
parentErr
:=
errors
.
New
(
"failed to ReceiveText"
)
// If there is no extant Conversation, create one.
...
...
@@ -270,9 +270,8 @@ func (w *wasmModel) ReceiveReaction(messageID message.ID, reactionTo message.ID,
return
uuid
}
func
(
w
*
wasmModel
)
UpdateSentStatus
(
uuid
uint64
,
messageID
message
.
ID
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
{
func
(
w
*
wasmModel
)
UpdateSentStatus
(
uuid
uint64
,
messageID
message
.
ID
,
timestamp
time
.
Time
,
round
rounds
.
Round
,
status
dm
.
Status
)
{
parentErr
:=
errors
.
New
(
"failed to UpdateSentStatus"
)
// FIXME: this is a bit of race condition without the mux.
...
...
@@ -323,8 +322,8 @@ func (w *wasmModel) UpdateSentStatus(uuid uint64,
}
// receiveHelper is a private helper for receiving any sort of message.
func
(
w
*
wasmModel
)
receiveHelper
(
newMessage
*
Message
,
isUpdate
bool
)
(
uint64
,
error
)
{
func
(
w
*
wasmModel
)
receiveHelper
(
newMessage
*
Message
,
isUpdate
bool
)
(
uint64
,
error
)
{
// Convert to jsObject
newMessageJson
,
err
:=
json
.
Marshal
(
newMessage
)
if
err
!=
nil
{
...
...
@@ -365,8 +364,7 @@ func (w *wasmModel) receiveHelper(newMessage *Message, isUpdate bool) (uint64,
}
// msgIDLookup gets the UUID of the Message with the given messageID.
func
(
w
*
wasmModel
)
msgIDLookup
(
messageID
message
.
ID
)
(
uint64
,
error
)
{
func
(
w
*
wasmModel
)
msgIDLookup
(
messageID
message
.
ID
)
(
uint64
,
error
)
{
resultObj
,
err
:=
indexedDb
.
GetIndex
(
w
.
db
,
messageStoreName
,
messageStoreMessageIndex
,
utils
.
CopyBytesToJS
(
messageID
.
Marshal
()))
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
indexedDb/utils.go
+
2
−
2
View file @
a77d62b8
...
...
@@ -157,8 +157,8 @@ func Put(db *idb.Database, objectStoreName string, value js.Value) (js.Value, er
return
result
,
nil
}
// Delete is a generic helper for removing values from the given
[idb.ObjectStore].
// Only usable by primary key.
// Delete is a generic helper for removing values from the given
//
[idb.ObjectStore].
Only usable by primary key.
func
Delete
(
db
*
idb
.
Database
,
objectStoreName
string
,
key
js
.
Value
)
error
{
parentErr
:=
errors
.
Errorf
(
"failed to Delete %s/%s"
,
objectStoreName
,
key
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment