Skip to content

Commit

Permalink
changed initialization proto
Browse files Browse the repository at this point in the history
  • Loading branch information
freeelancer committed Mar 11, 2024
1 parent dea147e commit 67596fe
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 96 deletions.
24 changes: 13 additions & 11 deletions integration-tests/src/modules/smartaccount/smartaccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ describe("Smartaccount Module (https://github.com/terra-money/core/tree/release/

// TODO: convert pubkey to base64 string similar to golang pubkey.Bytes()
const pubkeybb = pubkey as SimplePublicKey;
const pubkeyStr = pubkeybb.toData().key;
const pubkeyStr = pubkeybb.key;
// AsCe1GUUuW2cT63a35JRpGYaJ6/xIZXvrZRfRGsyxIhK
console.log(pubkeyStr)
const initMsg = Initialization.fromData({
senders: [],
account: controlledAccountAddress,
msg: pubkeyStr,
});
Expand Down Expand Up @@ -99,7 +97,7 @@ describe("Smartaccount Module (https://github.com/terra-money/core/tree/release/
}
});

test.only('Give smart account control to controller', async () => {
test('Give smart account control to controller', async () => {
try {
// give control to controller
const authMsg = new AuthorizationMsg(authContractAddress, initMsg);
Expand All @@ -113,9 +111,7 @@ describe("Smartaccount Module (https://github.com/terra-money/core/tree/release/
chainID: 'test-1',
gas: '400000',
});
let result = await LCD.chain1.tx.broadcastSync(tx, "test-1");
console.log("aaa")
console.log(result)
await LCD.chain1.tx.broadcastSync(tx, "test-1");
await blockInclusion();

// check if update authorization was successful
Expand All @@ -128,9 +124,16 @@ describe("Smartaccount Module (https://github.com/terra-money/core/tree/release/
pre_transaction: [],
fallback: false,
});
} catch (e:any) {
console.log(e)
expect(e).toBeUndefined();
}
});

test.only('Only controller should be able to sign', async () => {
try {
// signing with the controlledAccountAddress should now fail
tx = await wallet.createAndSignTx({
let tx = await wallet.createAndSignTx({
msgs: [
new MsgSend(
controlledAccountAddress,
Expand All @@ -141,7 +144,7 @@ describe("Smartaccount Module (https://github.com/terra-money/core/tree/release/
chainID: "test-1",
gas: '400000',
});
result = await LCD.chain1.tx.broadcastSync(tx, "test-1");
let result = await LCD.chain1.tx.broadcastSync(tx, "test-1");
expect(result.raw_log).toEqual("authorization failed: unauthorized");

// signing with the controller should now succeed
Expand All @@ -156,15 +159,14 @@ describe("Smartaccount Module (https://github.com/terra-money/core/tree/release/
chainID: "test-1",
gas: '400000',
});
console.log(controller.key.publicKey)
const deployerBalanceBefore = await LCD.chain1.bank.balance(deployerAddress);
result = await LCD.chain1.tx.broadcastSync(tx, "test-1");
console.log(result)
await blockInclusion();
const deployerBalanceAfter = await LCD.chain1.bank.balance(deployerAddress);
const deltaBalance = deployerBalanceAfter[0].sub(deployerBalanceBefore[0]);
expect(deltaBalance.toString()).toEqual("1uluna");
} catch (e:any) {
console.log(e)
expect(e).toBeUndefined();
}
});
Expand Down
5 changes: 2 additions & 3 deletions proto/terra/smartaccount/v1/wasm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import "gogoproto/gogo.proto";
option go_package = "github.com/terra-money/core/v2/x/smartaccount/types";

message Initialization {
repeated string senders = 1 [(gogoproto.jsontag) = "senders"];
string account = 2 [(gogoproto.jsontag) = "account"];
bytes msg = 3 [(gogoproto.jsontag) = "msg"];
string account = 1 [(gogoproto.jsontag) = "account"];
bytes msg = 2 [(gogoproto.jsontag) = "msg"];
}


Expand Down
10 changes: 0 additions & 10 deletions x/smartaccount/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (s *IntegrationTestSuite) TestMsgUpdateAuthorization() {

// create updateAuth msg
initMsg := types.Initialization{
Senders: []string{},
Account: acc.String(),
Msg: pkEncoded,
}
Expand Down Expand Up @@ -165,14 +164,5 @@ func (s *IntegrationTestSuite) CheckAuthorizationEqual(a []*types.AuthorizationM
s.Require().Equal(a[i].ContractAddress, b[i].ContractAddress)
s.Require().Equal(a[i].InitMsg.Msg, b[i].InitMsg.Msg)
s.Require().Equal(a[i].InitMsg.Account, b[i].InitMsg.Account)
if a[i].InitMsg.Senders == nil && b[i].InitMsg.Senders == nil {
return
} else if a[i].InitMsg.Senders == nil {
s.Require().Len(b[i].InitMsg.Senders, 0)
} else if b[i].InitMsg.Senders == nil {
s.Require().Len(a[i].InitMsg.Senders, 0)
} else {
s.Require().Equal(a[i].InitMsg.Senders, b[i].InitMsg.Senders)
}
}
}
88 changes: 16 additions & 72 deletions x/smartaccount/types/wasm.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 67596fe

Please sign in to comment.